Download Shine.Logging.zip - 24.38 KB Introduction

This is an instrumentation library, which uses Aspects Oriented Programming. This library can able to log Performance, Trace and Errors. As of now the out put is restricted only to console. Users can enhance this library to write logs to file systems.

Background

I'm involving in a project were WCF services are consuming considerable amout of time for processing. I though about an instrumentation library which could able to instrument the performance logs and the out come is this.

Using the code

Library exposes two manager classes named LogManager and LogInfoManager. LogManager class exposses GetLogger method which accept Type. Logger is persisted in LoggerRepository for future use maintaining key as namespace. Regarding with namespace it also maintain parent child relation and log messages are maintain in the queue in MessageQueue class.

Those logged messages can be retrieved by using LogInfoManager and can be saved to the file system. Present implemetation is showing log message to console only, for simplicity.

Following code depicts how to use this library for logging error messages.

 
public void ErrorDebugTest()
{
try
   {  

    throw new Exception("Custom exception");
   }

catch(Exception ex)
{
   LogManager.GetLogger(this.GetType()).Log(ex);
           
   //Write to file system from library. TODO.
    foreach (ErrorLogMessage message in LogInfoManager.ErrorMessages){
             

    Console.WriteLine(message.MessageText);
}

}

}

There are three Attribute classes provided, one for Class level and other for Methods level.

For more information of AOP implementation please follow this link http://searchwindevelopment.techtarget.com/tip/Aspect-oriented-programming-AOP-and-the-NET-Framework.

Implementation in our demo application will look like this.

[PerformanceLogger]
[TraceLogger]
 
public void PerformanceDebugTest()
{
for (int i = 0; i < 100; i++)
{           
Console.WriteLine(i);

}
}
}

History

        This is Version1.0. I will come with more updates.

Thanks

推荐.NET配套的通用数据层ORM框架:CYQ.Data 通用数据层框架