Instantiating Loggers
If you use the ConfigLogger, it may not be necessary for you to instantiate any additional loggers in your code. However, the ConfigLogger doesn't support every possible Logger. So there may be occasions when you must instantiate Loggers in your code.
There are numerous types of Loggers provided in the framework. Here are just a few examples.
A logger that writes to the console
Logger logger = TextWriterLogger.NewConsoleLogger();
A logger that writes to a file
Logger logger = new FileLogger("c:\\myLogFiles\\myLog.log");
A logger that writes Serialized log entries to a socket
Logger logger = new SerialSocketLogger("SomeHost.com", portNumber);
A logger that writes to numerous other loggers
This type of logger, the CompositeLogger, will probably be the main logger for your application. You can then put other, more specific loggers inside this one.
/* first instantiate some basic loggers */
Logger consoleLogger = TextWriterLogger.NewConsoleLogger();
Logger fileLogger = new FileLogger("c:\\mylogfiles\\mylog.log");
Logger socketLogger = new SerialSocketLogger("SomeHost.com", 12345);
/* now instantiate a CompositeLogger */
CompositeLogger logger = new CompositeLogger();
/* add the basic loggers to the CompositeLogger */
logger.AddLogger("console", consoleLogger);
logger.AddLogger("file", fileLogger);
logger.AddLogger("socket", socketLogger);
/* now all logs to logger will automatically be sent to the contained loggers as well */
Using the InsistentLogger
The InsistentLogger provides the functionality of retrying to log when a logger fails. For example, if a SerialSocketLogger was unable to connect to a server socket, then an InsistentLogger would automatically provide the retrying capability. Using it is simple.
/* create my basic logger */
Logger logger = new SerialSocketLogger( "SomeHost.com", 12345 );
/* - wrap in an InsistentLogger
- have a backup of 200 LogEntries
- retry logging every 60 seconds */
logger = new InsistentLogger( logger, 200, 60 );
/* now I can log to logger just like any other logger */