Click here to Skip to main content
Licence LGPL3
First Posted 28 Oct 2010
Views 5,421
Bookmarked 3 times

Nlog configuration

By | 28 Oct 2010 | Technical Blog
I&#8217;ve switched from my own logging framework to nlog. NLog seems quite flexible is under active development and suits my needs perfectly. I&#8217;m logging both to the console and to files using the following configuration file: <section name="nlog" type="NLog.Config.ConfigSectionHandler, &#82
A Technical Blog article. View original blog here.[^]

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 get’s 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
Share and Enjoy:PrintDiggStumbleUpondel.icio.usFacebookYahoo! BuzzTwitterGoogle BookmarksDZoneLinkedInSlashdotTechnorati

License

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

About the Author

jgauffin

Founder
Gauffin Interactive AB
Sweden Sweden

Member

Follow on Twitter Follow on Twitter
Freelance developer/architect with a passion for code quality, architecture, refactoring, networking and threading.
 
Solid skills in .NET/C#/MVC3
 
Blog: http://blog.gauffin.org

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120517.1 | Last Updated 28 Oct 2010
Article Copyright 2010 by jgauffin
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid