Class Log
A simple logging system. Writes to an in-memory buffer and a plain text file. Allows additional handlers to be registered (e.g., for console or GUI output).
Namespace: NanoByte.Common
Assembly: NanoByte.Common.dll
Syntax
public static class Log : Object
Methods
add_Handler(LogEntryEventHandler)
Declaration
public static void add_Handler(LogEntryEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
LogEntryEventHandler | value |
Debug(Exception)
Writes information to help developers diagnose problems to the log.
Declaration
public static void Debug(Exception exception)
Parameters
Type | Name | Description |
---|---|---|
Exception | exception |
Debug(String, Exception)
Writes information to help developers diagnose problems to the log.
Declaration
public static void Debug(string message, Exception exception = null)
Parameters
Type | Name | Description |
---|---|---|
String | message | |
Exception | exception |
Error(Exception)
Writes a critical error that should be attended to to the log.
Declaration
public static void Error(Exception exception)
Parameters
Type | Name | Description |
---|---|---|
Exception | exception |
Error(String, Exception)
Writes a critical error that should be attended to to the log.
Declaration
public static void Error(string message, Exception exception = null)
Parameters
Type | Name | Description |
---|---|---|
String | message | |
Exception | exception |
GetBuffer()
Returns the log lines collected in the in-memory buffer.
Declaration
public static string GetBuffer()
Returns
Type | Description |
---|---|
String |
Info(Exception)
Writes nice-to-know information to the log.
Declaration
public static void Info(Exception exception)
Parameters
Type | Name | Description |
---|---|---|
Exception | exception |
Info(String, Exception)
Writes nice-to-know information to the log.
Declaration
public static void Info(string message, Exception exception = null)
Parameters
Type | Name | Description |
---|---|---|
String | message | |
Exception | exception |
ReadLastErrorFrom(String, Nullable<Int32>)
Tries to read the last error log line written by another process.
Declaration
public static string ReadLastErrorFrom(string appName, Nullable<int> processId = null)
Parameters
Type | Name | Description |
---|---|---|
String | appName | The name of the app to get a log line for. |
Nullable<Int32> | processId | The process ID to get a log line for. Leave |
Returns
Type | Description |
---|---|
String |
remove_Handler(LogEntryEventHandler)
Declaration
public static void remove_Handler(LogEntryEventHandler value)
Parameters
Type | Name | Description |
---|---|---|
LogEntryEventHandler | value |
Warn(Exception)
Writes a warning that doesn't have to be acted upon immediately to the log.
Declaration
public static void Warn(Exception exception)
Parameters
Type | Name | Description |
---|---|---|
Exception | exception |
Warn(String, Exception)
Writes a warning that doesn't have to be acted upon immediately to the log.
Declaration
public static void Warn(string message, Exception exception = null)
Parameters
Type | Name | Description |
---|---|---|
String | message | |
Exception | exception |
Events
Handler
Invoked when a new entry is added to the log. Only the newest (last) registered handler is invoked. Console output is used as a fallback if no handlers are registered.
Declaration
public static event LogEntryEventHandler Handler
Event Type
Type | Description |
---|---|
LogEntryEventHandler |