Looking for perfect logger output

September 26th, 2007

When coding (C#), I often encounter a common problem – which logger would be the best? Maybe log4net, maybe one from Microsoft.EnterpriseLibrary, maybe my own one? The answer is simpler that someone could imagine – this one which can produce clean and nice looking output. A log file is usually read by humans so it’s a must for a logger to produce something that is easy to search through.

I am really pissed off when see a bloated logger with many “fantastic” functions like mail sending, multithreading, thread-safety and many others… whose output looks like vomit. I will not present a sample by courtesy to my friend ;)

But take look at this one below. It’s not a perfect output but isn’t it clear and easy to read?

[DBG] 2007-09-25 12:10:32 - Initialization of an object
[DBG] 2007-09-25 12:10:35 - Loading data
[ERR] 2007-09-25 12:10:35 - System.NullReferenceException: Object reference not set to an instance of an object
    at Microsoft.BizTalk.Deployment.BizTalkAssembly.GetConnectedPorts(BtsCatalogExplorer explorer, String pipelineFullyQualifiedName)
    at Microsoft.BizTalk.Deployment.BizTalkAssembly.RemovePortsUsingPipelines()
    at Microsoft.BizTalk.Deployment.BizTalkAssembly.RemovePipelines()
    at Microsoft.BizTalk.Deployment.BizTalkAssembly.Remove()
    at Microsoft.BizTalk.Deployment.BizTalkAssembly.RemoveNamedModule(String
server, String database, String assemblyName, String assemblyVersion, String
assemblyCulture, String assemblyPublicKeyToken, ApplicationLog log)
[ERR] 2007-09-25 12:10:38 - System.NullReferenceException: Object reference not set to an instance of an object
    at Controls_X_YZ.MethodXYZ(Bar bar) in c:\code.ascx.cs:line 256
[INF] 2007-09-25 12:11:00 - Mail with an error has been sent

What kind of information should be logged in your opinion? Which kind of text formatting do you prefer?

One Response to “Looking for perfect logger output”

  1. Per Lundberg says:

    I definitely agree with you, logging output should be READABLE. This is an area where I feel GNU/Linux and similar systems have an advantage over Microsoft; the log files there are simply more mature, probably because they are used in a greater extent. But try to install Microsoft Biztalk Server for example, get an error and look at the log file… it is not very beautiful.

    So, you are completely right, IMO. :-)

    Best regards,
    Per

Leave a Reply

Designed by SirMike © All rights reserved

Valid XHTML 1.0! Valid CSS!

Powered by Rootnode