Skip to content

Logging Example

Jim Schaad edited this page Jul 7, 2017 · 1 revision

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.

Selection of a log manager

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();

Level of logging to be used

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;

Filtering logging based on the type class

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.

Setting up the default log to file

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;

Clone this wiki locally