Click here to Skip to main content
13,004,091 members (113,712 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

18.8K views
5 bookmarked
Posted 28 Oct 2010

Nlog Configuration

, 28 Oct 2010
Rate this:
Please Sign up or sign in to vote.
Nlog configuration

I’ve switched from my own logging framework to nlog. NLog seems quite flexible, is under active development and suits my needs perfectly. I’m logging both to the console and to files using the following configuration file:

<configSections>
  <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog" />
</configSections>

<nlog xmlns=" http://www.nlog-project.org/schemas/NLog.xsd"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" throwExceptions="true"
  internalLogFile=" Nlog.txt">
  <targets>
    <target name="file" xsi:type="File"
    layout="${longdate} ${threadid:padding=3} ${level:padding=-30}
    ${logger:padding=-30} ${message} ${exception:format=tostring}"
    fileName="${basedir}/logs/${shortdate}.txt"/>
    <target name="errors" xsi:type="File"
    layout="${longdate} ${threadid:padding=3} ${level:padding=-30}
    ${logger:padding=-30} ${message} ${exception:format=tostring}"
    fileName="${basedir}/logs/${shortdate}.errors.log" />
    <target name="console" xsi:type="ColoredConsole"
            layout="${date:format=HH\:MM\:ss} ${threadid:padding=3}
            ${logger:padding=-30} ${message}" />
  </targets>
  <rules>
    <logger name="*" minlevel="Trace"
    writeTo="file, console" />
    <logger name="*" minLevel="Error"
    writeTo="errors" />
  </rules>
</nlog>

The console gets colored output looking like this:

10:07:41  10 AppDog.Monitor    Checking AppDog.Monitoring.MonitoredApplication

And file syntax:

2010-07-03 10:22:56.4218  10 Trace   AppDog.Monitor   Checking AppDog.Monitoring.MonitoredApplication

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

Share

About the Author

jgauffin
Founder Gauffin Interactive AB
Sweden Sweden
Founder of OneTrueError, a .NET service which captures, analyzes and provide possible solutions for exceptions.

blog | twitter

You may also be interested in...

Comments and Discussions

 
Generalgood information Pin
Southmountain26-Mar-16 11:19
memberSouthmountain26-Mar-16 11:19 
GeneralMy vote of 3 Pin
bth_vijay2-Mar-13 7:49
memberbth_vijay2-Mar-13 7:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170627.1 | Last Updated 28 Oct 2010
Article Copyright 2010 by jgauffin
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid