---
title: "Most useful NLog configurations"  
description: "Most useful NLog configurations"  
author: "Anonymous User"  
published: 2013-04-17  
updated: 2013-04-17  
canonical: https://www.mindstick.com/forum/775/most-useful-nlog-configurations  
category: ".net"  
tags: [".net"]  
reading_time: 2 minutes  

---

# Most useful NLog configurations

Hi Everyone!

What are the best or most [useful](https://www.mindstick.com/articles/12694/how-dolomite-mineral-is-useful-in-human-life) configurations for logging with NLog? (These can be simple or [complex](https://yourviews.mindstick.com/audio/1142/understanding-the-complex-factors-influencing-mental-health), as long as they're useful.)

I'm [thinking](https://www.mindstick.com/blog/11889/how-to-change-your-thinking-paradigm) of examples like automatically [rolling](https://answers.mindstick.com/qa/38134/by-whom-was-the-rolling-plan-for-backward-country-suggested) over [log files](https://www.mindstick.com/interview/34182/compress-old-log-files-e-g-zip-after-7-days) at a certain size, changing the layout (log [message](https://www.mindstick.com/forum/12802/show-confirmation-message-yes-or-no-in-asp-dot-net)) whether or not there is an [exception](https://www.mindstick.com/articles/1824/objective-c-exception-handling), escalating the log level once an error has occurred, etc.

Here are some links:

- File target examples
- [NLog Demo](https://github.com/jkowalski/NLog/blob/master/examples/NLogDemo/NLog.config)
- [Examples in the source](http://github.com/jkowalski/NLog/tree/master/examples/targets/Configuration)

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)!

## Replies

### Reply by AVADHESH PATEL

Hi Ezra!\
Treating exceptions differently\
We often want to get more information when there is an exception. The following configuration has two targets, a file and the console, which filter on whether or not \
there is any exception info. (EDIT: Jarek has posted about a new method of doing this in vNext.)\
The key is to have a wrapper target with xsi:type="FilteringWrapper" condition="length('${exception}')>0"\
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.mono2.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true" internalLogLevel="Warn" internalLogFile="nlog log.log" > <variable name="VerboseLayout" value="${longdate} ${level:upperCase=true} ${message} (${callsite:includSourcePath=true})" /> <variable name="ExceptionVerboseLayout" value="${VerboseLayout} (${stacktrace:topFrames=10}) ${exception:format=ToString}" />\
<targets async="true"> <target name="file" xsi:type="File" fileName="log.log" layout="${VerboseLayout}"> </target>\
<target name="fileAsException" xsi:type="FilteringWrapper" condition="length('${exception}')>0"> <target xsi:type="File" fileName="log.log" layout="${ExceptionVerboseLayout}" /> </target>\
<target xsi:type="ColoredConsole" name="console" layout="${NormalLayout}"/>\
<target xsi:type="FilteringWrapper" condition="length('${exception}')>0" name="consoleException"> <target xsi:type="ColoredConsole" layout="${ExceptionVerboseLayout}" /> </target> </targets>\
<rules> <logger name="*" minlevel="Trace" writeTo="console,consoleException" /> <logger name="*" minlevel="Warn" writeTo="file,fileAsException" /> </rules>\
</nlog>\


---

Original Source: https://www.mindstick.com/forum/775/most-useful-nlog-configurations

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
