Solutions for basic logging

September 25, 2006

The application I am creating for my project is a Windows Service, therefore I need to maintain a basic log of events in case there are technical issues. From the start I wanted to create an XML file that would hold this information, the reason for choosing XML being that it does not matter how the log file is to be used (it can be directly fed to a database, or viewed using a viewer). It’s just a simple, portable format.

The problem with maintaining an XML log is the overhead of appending a record to the file. Each time I need to append an entry the whole document must be loaded into memory and parsed. Quite alot of memory usage and processing to write a single line of text to a document!

The idea of using XML fragments seems to be the perfect balance as it allows valid XML to be appended to a file as you would with regular text. This example identifies this solution and provides an example.

Another solution, which I havn’t tried but looks very interesting is the technique identified in the post: Appending XML files and confusing disposables. This solution allows XML to be appended to an XML document without loading it into memory.

And finally, there is the log4net framework. At the moment I’m leaning more towards log4net due to the simplicity. Logging isn’t of key importance to my project so it’s important I don’t spend too much time on it 🙂 Appending to a plain text file is actually enough for me, but It’s good to evaluate the options.

My service has to read from an XML file.

Advertisements

One Response to “Solutions for basic logging”


  1. […] Solutions for basic logging […]


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: