Cisco Cisco Computer Telephony Integration Option 8.5 Developer's Guide

Page of 490
   
B-6
CTI OS Developer’s Guide for Cisco Unified Contact Center Enterprise
Release 8.5(3)
Appendix B      CTI OS Logging
Logging and Tracing (.NET)
Using the Default Logging Mechanism
You can use the .NET CIL LogWrapper class to implement logging to the system console or to a file. 
The LogWrapper class registers itself as an event listener and creates a log file.
How to Log Trace Events Using the LogWrapper Class
To log trace events using the LogWrapper class:
Step 1
Create an instance of the LogWrapper class, passing the following arguments:
logFileName - Name of file in which to write trace events .
fileMaxSize - The maximum size of the log file.
numberArchivesFiles - Maximum number of log files that can exist in the log file directory before 
the logging mechanism starts overwriting old files.
numberDaysBeforeFileExpired - Maximum number of days before a log file is rolled over into a new 
log file regardless of the size of the file.
The following code snippet creates an instance of the LogWrapper class that writes trace events to 
MyLogFile.txt. When MyLogFile.txt reaches 2048 KB, a new log file is created. The Logger creates a 
maximum of 20 log files in the log file directory before overwriting existing files. After 10 days, the log 
file is rolled over into a new log file regardless of its size.
// Create a LogWrapper. This will create a file and start 
// listening for log events to write to the file.
String logFileName                 = "MyLogFile.txt";
int    fileMaxSize                 = 2048;
int    numberArchivesFiles         = 20;
int    numberDaysBeforeFileExpired = 10;
m_logWrapper = new LogWrapper(logFileName, fileMaxSize, numberArchivesFiles, 
numberDaysBeforeFileExpired);
Step 2
In your application, write trace events. The following example traces a message at the given trace level 
for the given method. Set the trace level to the desired trace mask. Trace masks are defined in the Logger 
class. See 
Table B-1
 for a list of available trace mask values.
protected internal static void MyTrace (
int traceLevel,
string methodName,
string msg)
{
if ( m_logger.IsTraceMaskEnabled(traceLevel) )
{
string tracsMsg = string.Format("{0}: {1}", methodName,
msg) ;
m_logger.Trace(traceLevel, msg) ;
}
}
The CTI Toolkit Combo Desktop .NET sample application included with the CTI OS toolkit shows how 
to use the CIL's LogWrapper class in the context of a complex softphone application.
Table B-1
 lists the trace masks available in the .NET CIL.