Skip to content

Instantly share code, notes, and snippets.

@PhilMurwin
Created February 28, 2014 19:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PhilMurwin/9278247 to your computer and use it in GitHub Desktop.
Save PhilMurwin/9278247 to your computer and use it in GitHub Desktop.
Basic NLog configuration file with a file target for Info+ and an email target for error+
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<!--
See http://nlog-project.org/wiki/Configuration_file
for information on customizing logging rules and outputs.
-->
<variable name="linePrefix" value="${date:format=yyyy-MM-dd HH\:mm\:ss} ${pad:padding=5:inner=${uppercase:${level}}} ${callsite:IncludeSourcePath=false} - "/>
<variable name="exceptionFormat" value="${onexception:${newline}EXCEPTION OCCURRED\:${exception:format=type,message,method,stacktrace:maxInnerExceptionLevel=5:innerFormat=shortType,message,method}}"/>
<variable name="appName" value="PromoPort"/>
<targets>
<!-- add your targets here -->
<target xsi:type="File"
name="default"
fileName="${basedir}/logs/${appName}_${shortdate}.log"
layout="${linePrefix}${message}${exceptionFormat}" />
<target xsi:type="Mail"
name="ErrEmail"
smtpServer="192.168.2.75"
from="noreply@example.com"
to="noreply@example.com"
subject="${appName}: Exception Error"
body="${linePrefix}${message}${newline}${exceptionFormat}"/>
</targets>
<rules>
<!-- add your logging rules here -->
<logger name="*" minlevel="Info" writeTo="default" />
<logger name="*" minlevel="Error" writeTo="ErrEmail" />
</rules>
</nlog>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment