Adding log capabilities to your .NET application

log

When you want to create a detailed log of communication between the client and server, you can either handle the CommandResponse events that exist in almost components or add a log listener to the XTrace class.

The following steps illustrate how to add log capabilities to your .NET application by adding a log listener to the XTrace class:

  • Make sure you have referenced the required assembly ComponentPro.Common.dll
  • Add the following code at the beginning of your application. As it adds the file log listener to the XTrace static class, you should call this code segment once only:
    // Set the log level.
    ComponentPro.Diagnostics.XTrace.Default.Level = ComponentPro.Diagnostics.TraceEventType.Verbose;
    // By default the AutoFlush property is true. 
    // If you wish to turn it off, just set it to false as follows:
    // ComponentPro.Diagnostics.XTrace.AutoFlush = false;
    
    // Add the UltimateTextWriterTraceListener listener to write to a file.
    ComponentPro.Diagnostics.XTrace.Default.Listeners.Add(
        new ComponentPro.Diagnostics.UltimateTextWriterTraceListener("c:\\temp\\log.log"));
    
    // You can also write log to a Console window with the following code:
    ComponentPro.Diagnostics.XTrace.Default.Listeners.Add(new ComponentPro.Diagnostics.UltimateConsoleTraceListener());
    
    // Or write log to the Output window and .NET trace listeners:
    ComponentPro.Diagnostics.XTrace.Default.Listeners.Add(new ComponentPro.Diagnostics.UltimateOutputTraceListener());
    
    ' Set the log level.
    ComponentPro.Diagnostics.XTrace.Default.Level = ComponentPro.Diagnostics.TraceEventType.Verbose
    ' By default the AutoFlush property is true. 
    ' If you wish to turn it off, just set it to false as follows:
    ' ComponentPro.Diagnostics.XTrace.AutoFlush = false;
    
    ' Add the UltimateTextWriterTraceListener listener to write to a file.
    ComponentPro.Diagnostics.XTrace.Default.Listeners.Add(New ComponentPro.Diagnostics.UltimateTextWriterTraceListener("c:\temp\log.log"))
    
    ' You can also write log to a Console window with the following code:
    ComponentPro.Diagnostics.XTrace.Default.Listeners.Add(New ComponentPro.Diagnostics.UltimateConsoleTraceListener())
    
    ' Or write log to the Output window and .NET trace listeners:
    ComponentPro.Diagnostics.XTrace.Default.Listeners.Add(New ComponentPro.Diagnostics.UltimateOutputTraceListener())
    

45-Day Money Back Guarantee

We will refund your full money in 45 days
if you are not satisfied with our products

Buy Now

Dont miss out Get update on new articles and other opportunities