-
Notifications
You must be signed in to change notification settings - Fork 20
Logging Example
The system has a built in logging system that it uses to log internal events. The system is also available to callers of the system to log information as well.
When the system loads and starts, it will select either the CommonLoggingManager or the ConsoleLogManager. This depends on if the common logging modules are installed for the application to use.
If a different log manager is desired, or if the application wants to change the logging manager part way through running a program, it can be done by setting the LogManager.Instance parameter. This only affects logging managers starting at that point. If a manager has previously been created for an object, then it will continue to use that old manager. Many, but not all, of the logging managers used here are assigned to static class members and will therefore be created when the first instance of the class is created or a static member of the class is referenced.
The following would force the console log manager to be used no matter what.
LogManager.Instance = new ConsoleLogManager();
There are a number different logging levels that can be used. These are defined in the LogLevel enumeration. Changing the logging level is a dynamic operation which affects all current loggers. The default logging level is None. To change it to Info, use the following line.
LogManager.Level = LogLevel.Info;
New as of 1.1.6
Two properties on the LogManager class are available to include or exclude specific types when doing logging. This allows for including or excluding specific classes from the log output.
New as of 1.1.6
A file based log manager has been created called FileLogManager so that systems which do not have consoles can get a log created for debugging purposes.
LogManager.Instance = new FileLogManager(textWriter);
NOTE: in 1.1.5 you can do this by
Console.LogStream = textWriter;