Tuesday, May 10, 2011

Log Parser

Just found out about Log Parser 2.2 from Microsoft, and while I was at it, i grabbed Visual Log Parser from CodePlex for a nice GUI (who likes cl right?)

This is simple app that I found out while trying to understand by IIS was recycling too many times and browsing this post.

It looks like you can query your EventViewer and a ton of other Log repositories just like a regular SQL database:

Select top 100 *
from \\server\System where SourceName = 'W3SVC'
and EventID in (1009;1010;1011;1074;1077;1078;1079;1080;1117)
order by timegenerated desc

Better than scrolling up and down right? You can even build up some VBS or something else to have some real time data from your logging. And this will work for different log platforms.


Remote Log4Net

You probably know this already, or this might not come as a surprise but enabling log4net to log to a remote place is really simple.

We had a scenario of only one front end with custom systems using log4net, but we needed to add a second front end, and with that the question about what to do about logging.

I wasn't aware how simple is to enable remote logging on log4net. So, heads up if you were like me:

Get log4net Remove Logging Service at CodePlex (you can get the source and change at your will), after install this will create a listener service where you want to store your remote log repository.

Then, at your local clients just change the appender to something like this

<appender name="remotAppend" type="log4net.Appender.RemotingAppender" >
<sink value="tcp://remoteserver:port/Log4netRemotingServerService" />
<lossy value="false" />
<bufferSize value="10" />
<onlyFixPartialEventData value="true" />
</appender>

At your Remote repository use your favorite appender, RollingLogFileAppender or whatever.
Remember to add the hostname property to your layout type: (%-10property{log4net:HostName}).

Something like this:

<appender name="RollLogAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\LOGS\MYAPP.log.txt" />
<appendToFile value="true" />
<rollingStyle value="Date" />
<encoding value="UTF-8" />
<datePattern value="'.'yyyy'.'MM'.'dd'.'HH'.log.txt'" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date (%-10property{log4net:HostName}) [%thread] %-5level %logger - %message%newline" />
</layout>
</appender>

Maybe you could do without this Codeplex service, but since it was so simple and the component is working fine I didnt waste any time looking for alternatives.

If you dont agree, please comment, shed some light :) Thank you.