My Thoughts & Views

Logging Errors with NLog a .NET Logging Library

Posted on: March 19, 2009

NLog is a .NET Logging Library, 

Official Site mentions it as follows,

NLog is a .NET logging library designed with simplicity and flexibility in mind. With NLog you can process diagnostic messages emitted from any .NET language, augment them with contextual information, format them according to your preference and send them to one or more targets.

Using it is very easy. Following steps helps you to get started.

(For Visual Studio 2008, Web Applications)
1. Download and install NLog Library

2. If you are using Visual Studio 2008, follow this step as mentioned in my earlier post, to fix issue with Intellisense.
3. Add reference to NLog.dll.
4. Add the following Entries to web.config

5. Add  following entries to your code behind file

(for C#)

using NLog;
using NLog.Targets;
using NLog.Config;
using NLog.Win32.Targets;
6.  Create a Logger object as below in your code behind file
catch(Exception ex)
    Logger errLogger = LogManager.GetLogger(“*”);
7. If you see, i have passed * as an argument to GetLogger method, please refer web.config entry, i have mentioned logger name as *.
8. This will log exceptions to  /Logs/Log.txt
If you encounter any problems then let me know.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

%d bloggers like this: