| Back | Main view

Logging in IMiS/Storage Connector .NET

Product:IMiS/Storage Connector .NET
Release:3.1.1204
Date:05/10/2012

Case: IMiS/Storage Connector .NET implements it's own logging with the use of either internal log handler or custom log handler(s). This article explains internal logging, the use of custom log handlers, logging level and output formating.

Description:

Internal logging

IMiS/Storage Connector .NET provides internal logging that can be enabled with by setting LogInternal property on an instance of the IMiS.StorageConnector.StorageConnector class to true. IMiS/Storage Connector uses IMiS.Diagnostics.FileLogHandler from imisbase.net.dll assembly to create IMiS.StorageConnector.log file in the system temporary folder.

C#
 
// Get an instance of the IMiS/Storage Connector
StorageConnector sc = StorageConnector.Instance;

// Enable internal logger
sc.LogInternal = true;
 
Custom log handlers

Users can enable custom logging in IMiS/Storage Connector .NET with a custom log handler attached to the IMiS/Storage Connector logger using LogHandlers property's Add() method. Log handlers are classes derived from System.Diagnostics.TraceListener class or IMiS.Diagnostics.LogHandler class, found in imisbase.net.dll assembly, that extends formatting output options for plain and error log entries. Output is determined by the log handler. Log messages can be written to a file, console or system event log for example.

For example, to create a file log, you can use either System.Diagnostics.TextWriterTraceListener or IMiS.Diagnostics.FileLogHandler instance as the log handler.

C#
 
// Get an instance of the IMiS/Storage Connector
StorageConnector sc = StorageConnector.Instance;

// Create custom log handler
IMiS.Diagnostics.FileHandler fileLog = new IMiS.Diagnostics.FileHandler(@"c:\isc.log", "File Log", 1000000, 10, FileLogOptions.Append); // file handler that outputs to rotating file log

// Add log handler to IMiS/Storage Connector logger
sc.LogHandlers.Add(fileLog);
 
Logging level & output formatting

Users can set the logging level of the IMiS/Storage Connector .NET logger with the IMiS.Storageconnector.StorageConnector.LogLevel property. Use one of the System.Diagnostics.SourceLevels enumeration values to control logging output to log handlers. Enabling logging at a given level also enables logging at all higher levels. For example, setting logging level to System.Diagnostics.SourceLevels.Information will also log warning and error messages.

Custom log handler's output formatting can be set with the System.Diagnostics.TraceListener.TraceOutputOptions property and IMiS.Diagnostics.LogHandler.LogOutputOptions property. For example, IMiS/Storage Connector internal logging uses these options for detailed output that includes log entry date, time, process id, thread, source, class and method name, followed by the message.

C#
 
// Get an instance of the IMiS/Storage Connector
StorageConnector sc = StorageConnector.Instance;

// Set logging level of IMiS/Storage Connector logger
sc.LogLevel = System.Diagnostics.SourceLevels.Verbose;

// Create custom log handler
IMiS.Diagnostics.FileHandler fileLog = new IMiS.Diagnostics.FileHandler(@"c:\isc.log", "File Log", 1000000, 10, FileLogOptions.Append); // file handler that outputs to rotating file log
fileLog.LogOutputOptions |= IMiS.Diagnostics.LogOptions.SourceName; // outputs source name in the log entry

// Add log handler to IMiS/Storage Connector logger
sc.LogHandlers.Add(fileLog);
 
Related Documents:



| Back | Main view