The Log class handles script logging and error reporting
public class Log : InstanceInterfaceRemarks
A simple script for viewing the log messages might be:
Example
/* (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; }}Source: Examples/LogExample.cs in the Sansar 47.10.0 client ScriptApi snapshot.
Members at a glance
| Kind | Members |
|---|---|
| Fields | ConsoleHistory · MaximumMessageLength · MaximumTagLength |
| Properties | Messages |
| Methods | Clear · Write · WriteDebug |
Fields
ConsoleHistory
[System.Obsolete("Messages are no longer stored.", true)]
public const int ConsoleHistoryThe maximum number of messages to store on this console.
Value: int — The maximum number of messages stored by the console.
MaximumMessageLength
public const int MaximumMessageLengthThe maximum length of a log message.
MaximumTagLength
public const int MaximumTagLengthThe maximum length of the log message tag.
Properties
Messages
[System.Obsolete("Messages are no longer stored.", true)]
public IEnumerable<Log.Message> Messages { get; }All current log messages.
Value: IEnumerable<Log.Message> — All currently stored log messages.
Methods
Clear
[System.Obsolete("Messages are no longer stored.", true)]
public void Clear()Clears all messages in this console.
Remarks
Messages cannot be restored.
[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 | The LogLevel to clear from the log. Multiple loglevels can be cleared in a single cal. |
Remarks
Messages cannot be restored.
[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 | The ScriptId to clear from the log. |
Remarks
Messages cannot be restored.
[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 | The tag to clear from the log. |
Remarks
Messages cannot be restored.
Write
public void Write(string message)Writes an info message to the server log.
| Parameter | Type | Description |
|---|---|---|
message | string | The message to be logged. |
Remarks
Log messages may be throttled.
public void Write(LogLevel logLevel, string message)Writes a message to the server log.
| Parameter | Type | Description |
|---|---|---|
logLevel | LogLevel | LogLevel of the message. |
message | string | The message to be logged. |
Remarks
Log messages may be throttled.
public void Write(string tag, string message)Writes an info message to the server log.
| Parameter | Type | Description |
|---|---|---|
tag | string | A freeform string tag for filtering the message. |
message | string | The message to be logged. |
Remarks
Log messages may be throttled.
public void Write(LogLevel logLevel, string tag, string message)Writes a message to the server log.
| Parameter | Type | Description |
|---|---|---|
logLevel | LogLevel | LogLevel of the message. |
tag | string | Tag for the message. |
message | string | Message to log. |
Remarks
Also tracks the sending script and the time. No messages are locally retained.
WriteDebug
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 | (Optional) The message to be logged. When left empty, it will only log caller information. |
tag | string | (Optional) A tag for the message. |
callerMemberName | string | Automatically populated with the name of the calling member (method or property). |
callerLineNumber | int | Automatically populated with the line number in the source code where the method was called. |
Remarks
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.
Generated from the Sansar 47.10.0 client ScriptApi snapshot.