Class Logger
A logger that logs messages originating from Realm. The default logger can be replaced by setting Default.
A few built-in implementations are provided by Console, Null, and Function(Action<string>),
but you can implement your own.
Namespace: Realms.Logging
Assembly: Realm.dll
Syntax
public abstract class Logger
Constructors
| Edit this page View SourceLogger()
Initializes a new instance of the Logger class.
Declaration
protected Logger()
Properties
| Edit this page View SourceConsole
Gets a Logger.ConsoleLogger that outputs messages to the default console. For most project types, that will be using WriteLine() but certain platforms may use different implementations.
Declaration
public static Logger Console { get; }
Property Value
Type | Description |
---|---|
Logger | A Logger instance that outputs to the platform's console. |
Default
Gets or sets a custom Logger implementation that will be used by Realm whenever information must be logged.
Declaration
public static Logger Default { get; set; }
Property Value
Type | Description |
---|---|
Logger | The logger to be used for Realm-originating messages. |
LogLevel
Gets or sets the verbosity of log messages.
Declaration
public static LogLevel LogLevel { get; set; }
Property Value
Type | Description |
---|---|
LogLevel | The log level for Realm-originating messages. |
Null
Gets a Logger.NullLogger that ignores all messages.
Declaration
public static Logger Null { get; }
Property Value
Type | Description |
---|---|
Logger | A Logger that doesn't output any messages. |
Methods
| Edit this page View SourceFile(string, Encoding?)
Gets a Logger.FileLogger that saves the log messages to a file.
Declaration
public static Logger File(string filePath, Encoding? encoding = null)
Parameters
Type | Name | Description |
---|---|---|
string | filePath | Path of the file to save messages to. The file is created if it does not already exists. |
Encoding | encoding | Character encoding to use. Defaults to UTF8 if not specified. |
Returns
Type | Description |
---|---|
Logger | A Logger instance that will save log messages to a file. |
Remarks
Please note that this logger is not optimized for performance, and could lead to overall sync performance slowdown with more verbose log levels.
Function(Action<LogLevel, string>)
Gets a Logger.FunctionLogger that proxies Log calls to the supplied function.
Declaration
public static Logger Function(Action<LogLevel, string> logFunction)
Parameters
Type | Name | Description |
---|---|---|
Action<LogLevel, string> | logFunction | Function to proxy log calls to. |
Returns
Type | Description |
---|---|
Logger | A Logger instance that will invoke |
Function(Action<string>)
Gets a Logger.FunctionLogger that proxies Log calls to the supplied function. The message will already be formatted with the default message formatting that includes a timestamp.
Declaration
public static Logger Function(Action<string> logFunction)
Parameters
Type | Name | Description |
---|---|---|
Action<string> | logFunction | Function to proxy log calls to. |
Returns
Type | Description |
---|---|
Logger | A Logger instance that will invoke |
Log(LogLevel, string)
Log a message at the supplied level.
Declaration
public void Log(LogLevel level, string message)
Parameters
Type | Name | Description |
---|---|---|
LogLevel | level | The criticality level for the message. |
string | message | The message to log. |
LogImpl(LogLevel, string)
The internal implementation being called from Log(LogLevel, string).
Declaration
protected abstract void LogImpl(LogLevel level, string message)
Parameters
Type | Name | Description |
---|---|---|
LogLevel | level | The criticality level for the message. |
string | message | The message to log. |