# Log

Kind: Class · Namespace: Sansar.Script · Assembly: Sansar.Script.dll · Script API 47.10.0

<div class="api-meta">
<span class="api-kind api-kind-class" data-pagefind-filter="kind:Class">Class</span>
<span data-pagefind-filter="namespace:Sansar.Script">Namespace <a href="/scripting/api/sansar.script"><code>Sansar.Script</code></a></span>
<span>Inherits <a href="/scripting/api/sansar.script/instanceinterface">InstanceInterface</a></span>
</div>

<span id="T:Sansar.Script.Log"></span>

The Log class handles script logging and error reporting

```csharp
public class Log : InstanceInterface
```

## Remarks

A simple script for viewing the log messages might be:

## Example

```csharp title="LogExample.cs"
/* (C) Linden Research, Inc. All Rights Reserved. */

using Sansar.Script;
using Sansar.Simulation;

public class LogExample : SceneObjectScript
{
    public override void Init()
    {
        // Basic log message
        Log.Write(LogLevel.Info, "LogExample initialized");

        // Log with format parameters
        var sampleValue = "example";
        Log.Write(LogLevel.Warning, "Sample value: {0}", sampleValue);

        // Simulate a recoverable error to show LogLevel.Error usage.
        var success = TryDoWork();
        if (!success)
        {
            Log.Write(LogLevel.Error, "The sample work loop reported a failure.");
        }
    }

    private bool TryDoWork()
    {
        // Placeholder for sample logic
        return false;
    }
}
```

<p class="api-example-source">Source: <code>Examples/LogExample.cs</code> in the Sansar 47.10.0 client ScriptApi snapshot.</p>

## Members at a glance

| Kind | Members |
|---|---|
| **Fields** | [ConsoleHistory](#consolehistory) · [MaximumMessageLength](#maximummessagelength) · [MaximumTagLength](#maximumtaglength) |
| **Properties** | [Messages](#messages) |
| **Methods** | [Clear](#clear) · [Write](#write) · [WriteDebug](#writedebug) |

## Fields

### ConsoleHistory

<div class="api-card">
<span id="F:Sansar.Script.Log.ConsoleHistory"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Messages are no longer stored.", true)]
public const int ConsoleHistory
```

The maximum number of messages to store on this console.

**Value:** [int](https://learn.microsoft.com/dotnet/api/system.int32) — The maximum number of messages stored by the console.

</div>

### MaximumMessageLength

<div class="api-card">
<span id="F:Sansar.Script.Log.MaximumMessageLength"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 45.0.4</span></div>

```csharp signature
public const int MaximumMessageLength
```

The maximum length of a log message.

</div>

### MaximumTagLength

<div class="api-card">
<span id="F:Sansar.Script.Log.MaximumTagLength"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 45.0.4</span></div>

```csharp signature
public const int MaximumTagLength
```

The maximum length of the log message tag.

</div>


## Properties

### Messages

<div class="api-card">
<span id="P:Sansar.Script.Log.Messages"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Messages are no longer stored.", true)]
public IEnumerable<Log.Message> Messages { get; }
```

All current log messages.

**Value:** [IEnumerable&lt;Log.Message&gt;](https://learn.microsoft.com/dotnet/api/system.collections.generic.ienumerable-1) — All currently stored log messages.

</div>


## Methods

### Clear

<div class="api-card" id="clear-noargs">
<span id="M:Sansar.Script.Log.Clear"></span>
<span id="M:Sansar.Script.Log.Clear()"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Messages are no longer stored.", true)]
public void Clear()
```

Clears all messages in this console.

<details class="api-remarks"><summary>Remarks</summary>

Messages cannot be restored.

</details>

</div>

<div class="api-card" id="clear-loglevel">
<span id="M:Sansar.Script.Log.Clear(Sansar.Script.LogLevel)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Messages are no longer stored.", true)]
public void Clear(LogLevel logLevel)
```

Clears all messages in this console with the given logLevel.

| Parameter | Type | Description |
|---|---|---|
| `logLevel` | [LogLevel](/scripting/api/sansar.script/loglevel) | The LogLevel to clear from the log. Multiple loglevels can be cleared in a single cal. |

<details class="api-remarks"><summary>Remarks</summary>

Messages cannot be restored.

</details>

</div>

<div class="api-card" id="clear-scriptid">
<span id="M:Sansar.Script.Log.Clear(Sansar.Script.ScriptId)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Messages are no longer stored.", true)]
public void Clear(ScriptId scriptId)
```

Clears all messages in this console with the given ScriptId.

| Parameter | Type | Description |
|---|---|---|
| `scriptId` | [ScriptId](/scripting/api/sansar.script/scriptid) | The ScriptId to clear from the log. |

<details class="api-remarks"><summary>Remarks</summary>

Messages cannot be restored.

</details>

</div>

<div class="api-card" id="clear-string">
<span id="M:Sansar.Script.Log.Clear(System.String)"></span>
<div class="api-badges"><span class="api-badge api-deprecated">Deprecated</span></div>

```csharp signature
[System.Obsolete("Messages are no longer stored.", true)]
public void Clear(string tag)
```

Clears all messages in this console with the given tag.

| Parameter | Type | Description |
|---|---|---|
| `tag` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The tag to clear from the log. |

<details class="api-remarks"><summary>Remarks</summary>

Messages cannot be restored.

</details>

</div>

### Write

<div class="api-card" id="write-string">
<span id="M:Sansar.Script.Log.Write(System.String)"></span>

```csharp signature
public void Write(string message)
```

Writes an info message to the server log.

| Parameter | Type | Description |
|---|---|---|
| `message` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The message to be logged. |

<details class="api-remarks"><summary>Remarks</summary>

Log messages may be throttled.

</details>

</div>

<div class="api-card" id="write-loglevel-string">
<span id="M:Sansar.Script.Log.Write(Sansar.Script.LogLevel,System.String)"></span>

```csharp signature
public void Write(LogLevel logLevel, string message)
```

Writes a message to the server log.

| Parameter | Type | Description |
|---|---|---|
| `logLevel` | [LogLevel](/scripting/api/sansar.script/loglevel) | LogLevel of the message. |
| `message` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The message to be logged. |

<details class="api-remarks"><summary>Remarks</summary>

Log messages may be throttled.

</details>

</div>

<div class="api-card" id="write-string-string">
<span id="M:Sansar.Script.Log.Write(System.String,System.String)"></span>

```csharp signature
public void Write(string tag, string message)
```

Writes an info message to the server log.

| Parameter | Type | Description |
|---|---|---|
| `tag` | [string](https://learn.microsoft.com/dotnet/api/system.string) | A freeform string tag for filtering the message. |
| `message` | [string](https://learn.microsoft.com/dotnet/api/system.string) | The message to be logged. |

<details class="api-remarks"><summary>Remarks</summary>

Log messages may be throttled.

</details>

</div>

<div class="api-card" id="write-loglevel-string-string">
<span id="M:Sansar.Script.Log.Write(Sansar.Script.LogLevel,System.String,System.String)"></span>

```csharp signature
public void Write(LogLevel logLevel, string tag, string message)
```

Writes a message to the server log.

| Parameter | Type | Description |
|---|---|---|
| `logLevel` | [LogLevel](/scripting/api/sansar.script/loglevel) | LogLevel of the message. |
| `tag` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Tag for the message. |
| `message` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Message to log. |

<details class="api-remarks"><summary>Remarks</summary>

Also tracks the sending script and the time. No messages are locally retained.

</details>

</div>

### WriteDebug

<div class="api-card">
<span id="M:Sansar.Script.Log.WriteDebug(System.String,System.String,System.String,System.Int32)"></span>
<div class="api-badges"><span class="api-badge api-since">Added in 45.0.4</span></div>

```csharp signature
public void WriteDebug(
    string message,
    string tag,
    [System.Runtime.CompilerServices.CallerMemberName] string callerMemberName,
    [System.Runtime.CompilerServices.CallerLineNumber] int callerLineNumber
)
```

Writes a debug message to the server log, including caller information.

| Parameter | Type | Description |
|---|---|---|
| `message` | [string](https://learn.microsoft.com/dotnet/api/system.string) | (Optional) The message to be logged. When left empty, it will only log caller information. |
| `tag` | [string](https://learn.microsoft.com/dotnet/api/system.string) | (Optional) A tag for the message. |
| `callerMemberName` | [string](https://learn.microsoft.com/dotnet/api/system.string) | Automatically populated with the name of the calling member (method or property). |
| `callerLineNumber` | [int](https://learn.microsoft.com/dotnet/api/system.int32) | Automatically populated with the line number in the source code where the method was called. |

<details class="api-remarks"><summary>Remarks</summary>

Log messages may be throttled. WriteDebug(..) serves the same purpose as using Write(LogLevel.Debug, ..), while also including automatically populated caller information for debugging purposes.

</details>

</div>




<p class="api-generated" data-pagefind-ignore>Generated from the Sansar 47.10.0 client ScriptApi snapshot.</p>