Repository navigation
XML config include Example
Rolf Kristensen edited this page May 31, 2025
·
10 revisions
Example with a and in the XML config
File to be included.
Contains one target and needs ${productName}
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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
<targets>
<target name="file1" xsi:type="File" fileName="D:\logs\${productName}\${shortdate}.log"
layout="${time} [${level:uppercase=true}] |${logger}| ${message} ${exception}" />
targets>
nlog>
The main file.
e.g. in the root folder of your application. Contains in this example no targets, only , `
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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd">
<variable name="productName" value="myProduct"/>
<include file="D:\nlog-file.config" ignoreErrors="true" />
<variable name="myVar" value="myValue"/>
<rules>
<logger name="*" minlevel="Info" writeTo="file1" enabled="false" />
<logger name="PerformanceLogger" minlevel="Trace" writeTo="file1" enabled="false" />
rules>
nlog>
- Troubleshooting Guide - See available NLog Targets and Layouts: https://nlog-project.org/config
- Getting started
- How to use structured logging
- Troubleshooting
- FAQ
- Articles about NLog
-
All targets, layouts and layout renderers
Popular: - Using NLog with NLog.config
- Using NLog with appsettings.json