NLog is a free logging platform for .NET, Silverlight, and Windows Phone with rich log routing and management capabilities. It makes it easy to produce and manage high-quality logs for your applications regardless of their size or complexity. When you don't want to care about the archiving, and log formats then NLog is your friend. Using just a few configuration settings will enable everything for you. So let's get started.
First, download the appropriate version of Nlog that you'll be using in your application. Now when you have the desired library of Nlog just add the reference to your project. The next thing you need to do is put some configuration lines in the config file.
Register the NLog section in config.
<configuration>
<configSections>
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>
</configuration>
Note. keep in mind you're putting the config sections tag at the top of the Configuration file otherwise, you'll get an exception "Can not have more than one config section in the configuration" or something like that.
Next, you need to specify the Nlog section to be defined. The following is the sample code configuration of Nlog required to enable logging in your application.
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true" internalLogFile="c:\temp\nLog_internal_log_file.txt" internalLogLevel="Trace" internalLogToConsole="true">
<targets async="true">
<target name="file" xsi:type="File" keepFileOpen="false" fileName="C:\\Temp\\Test_Log.MyApplication.${shortdate}.txt" layout="${newline}${newline}${level}: ${message} ${exception:format=Message,StackTrace}" archiveFileName="C:\\Temp\\archives\Log.FaultDetectionSitePoller.{#####}.txt" lineEnding="Default" archiveAboveSize="1024000" archiveNumbering="Sequence" concurrentWrites="true" />
<target xsi:type="Database" name="database">
<connectionString>
data source=LABPC02;initial catalog=SampleDatabase;Integrated Security=SSPI;
</connectionString>
<commandText>
INSERT INTO Diagnostics
(Severity
,Message
,StackTrace
,User
,MachineName
)
VALUES ( @severity
, @message
, @stacktrace
, @User
, @machinename
)
</commandText>
<parameter name="@severity" layout="${level}" />
<parameter name="@message" layout="${message}" />
<parameter name="@machinename" layout="${machinename}" />
<parameter name="@User" layout="${windows-identity:domain=true}" />
<parameter name="@stacktrace" layout="${stacktrace}" />
</target>
</targets>
<rules>
<logger name="*" writeTo="file" />
<logger name="*" minLevel="OFF" appendTo="database" />
</rules>
</nlog>
In this section, we have a couple of things that I need to explain.
InternalLogFile
This is the file that Nlog will use for its own logging. It'll help you troubleshoot any issue with the NLog configuration of your project. It's optional and not required if you don't want to log the status of Nlog's internal stuff.

Suthahar JegatheesanPosted Feb 3, 2014, 7:45 AM
Hi,for me very new this ..i am trying to implement same into xamarin .can you please share me solution file
Amit ChoudharyPosted Dec 28, 2012, 2:30 AM
hmmm.. That means I wasn't aware about it earlier. So it's new for me sir and I found it very useful as compare to Log4net.
Mahesh ChandPosted Dec 27, 2012, 7:49 PM
It is very useful. However, NLog is not new. I've used it bunch of my projects. I started using it like 4-5 years ago :).