Sunday, October 28, 2012

Configuring NLog , a learn curve flattening guide

Low Level Design - To log or NLog

"Today’s post is dedicated to NLog – one of the logging libraries available for .NET developers. NLog has a lot of features and options and might seem complicated at first sight. Checking the examples should usually allay your fears but it will still take you some time to get along with NLog’s syntax and configuration. I will try to make the learning curve less sharp by providing you with configuration options that prove to be working in my projects. If you are new to NLog I recommend you to have a look at its tutorial before reading on.

I usually add NLog configuration to my web/app.config file in which case I need to define the nlog section at the beginning of the configuration file:

...

Conclusion

I hope the presented examples of NLog configurations will help you create your own set of logger layouts and targets that will best suit your needs. NLog has a lot of features and I advice you to have a look at its wiki and source code in order to know it better. Some hidden gems include: logging to performance counters and reading performance counters values; logging to a web service; rendering your logs in a form of xml, json or csv; log installers (for eventlogs or performance counters) and many more. As usual the code presented in this post is available for download on my codeplex page.

image..."

I've just recently started using NLog in a project and like it so far. I've used Trace, log4Net and a hand written logging and so far I'm liking NLog the best (with log4net a close second). A logging library library can be overkill sometimes, but what you need logged always seems to grow, doesn't it? So overkill quickly becomes just right...

I love how these libraries handle the simple things archiving/rolling/cleaning up log files. It's the little things that make me happy. :)

No comments: