In development after deploying application to test servers or production lots of bugs can be discovered only if You implemented a good logging or some logging at all.
I have found that there is 2 products dominating that is Log4Net and Ent.Lib Logging
Today I wanted to test only performance.
Used versions:
Log4Net 1.2.10
Microsoft Enterprise Library 5.0
Visual Studio 2010 Premium
.Net framework 3.5 (Sharepoint does not work with 4.0)
Testing process:
Creating console application that creates 10000 log Info level entries and measure time.
Creating Test Code
class Program
{
static void Main(string[] args)
{
DateTime d = DateTime.Now;
for (int n = 0; n < 10000; n++)
{
//Logging goes here
}
DateTime d2 = DateTime.Now;
Console.WriteLine(string.Concat("Finished: ", (d2-d).Milliseconds, "ms"));
Console.ReadKey();
}
}
Log4Net
1 Adding reference to
bin\net\2.0\release\log4net.dll
2 Configuring
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<param name="File"
<appender name="LogFileAppender" type="log4net.Appender.FileAppender,log4net" >
value="c:\\!\\log4net.txt" />
<param name="AppendToFile" value="true" />
<layout type="log4net.Layout.PatternLayout,log4net">
<param name="ConversionPattern" value="%d [%t] %-5p %c [%x] <%X{auth}> - %m%n" />
</layout>
</appender>
<root>
<priority value="ALL" />
<appender-ref ref="LogFileAppender" />
</root>
<category name="Log4NetTest.Program">
<priority value="ALL" />
</category>
</log4net>
</configuration>
3. Code
class Program
{
private static readonly ILog log = LogManager.GetLogger(typeof(Program));
static void Main(string[] args)
{
XmlConfigurator.Configure();
DateTime d = DateTime.Now;
for (int n = 0; n < 10000; n++)
{
//Logging goes here
log.Info(n);
}
DateTime d2 = DateTime.Now;
Console.WriteLine(string.Concat("Finished: ", (d2-d).Milliseconds, "ms"));
Console.ReadKey();
}
}
Microsoft Enterprise Library 5.0
1. Adding reference to Ent.Lib
Microsoft Enterprise Library 5.0\Bin\Microsoft.Practices.EnterpriseLibrary.Logging.dll
2. Configuring
3. Code
static void Main(string[] args)
{
DateTime d = DateTime.Now;
for (int n = 0; n < 10000; n++)
{
//Logging goes here
Logger.Write(n);
}
DateTime d2 = DateTime.Now;
Console.WriteLine(string.Concat("Finished: ", (d2 - d).Milliseconds, "ms"));
Console.ReadKey();
}
Results for 10K records (Keeping Log files after each test)
Nr Log4Net Ent.Lib
1 218ms 515ms
2 234ms 468ms
3 203ms 390ms
4 249ms 640ms
5 234ms 390ms
Results for 1M records(Deleted Log files after each test)
Nr Log4Net Ent.Lib
1 107ms 253ms
2 436ms 742ms
3 279ms 241ms
4 216ms 350ms
5 342ms 240ms
Conclusion:
Log4Net is lighter and faster but it lacks configuration manager like Ent.Lib provides. To make configuration file I had to google around and search for examples. Ent.Lib is a little slower, but configuration tool it compensates that with very easy way to create logging for Your application.
No comments:
Post a Comment