Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/NLogPublic

XML config include Example

Rolf Kristensen edited this pageMay 31, 2025 ·10 revisions

Example with a<include /> and<variable /> in the XML config

base file: d:\nlog-file.config

File to be included.Contains one target and needs${productName}

<?xml version="1.0" encoding="utf-8" ?><nlogxmlns="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"><!-- This file will be included.--><!--  Note: Attributes on the "nlog" element are ignored for this file, the ones of the main config will be used.--><!-- the variable ${productName} must be defined in the main nlog.config-->    <targets>      <targetname="file1"xsi:type="File"fileName="D:\logs\${productName}\${shortdate}.log"layout="${time} [${level:uppercase=true}] |${logger}| ${message} ${exception}" />  </targets>  </nlog>

nlog.config

The main file.e.g. in the root folder of your application. Contains in this example no targets, only<include />,,`

<?xml version="1.0" encoding="utf-8" ?><nlogxmlns="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"><!-- override productName in includes, so it could be used in d:\nlog-file.config-->  <variablename="productName"value="myProduct"/>                              <includefile="D:\nlog-file.config"ignoreErrors="true" /><!-- note: will be set after the include are loaded-->  <variablename="myVar"value="myValue"/>        <rules>          <loggername="*"minlevel="Info"writeTo="file1"enabled="false" />         <loggername="PerformanceLogger"minlevel="Trace"writeTo="file1"enabled="false" /><!-- not enabled, only when tracing-->  </rules></nlog>

-Troubleshooting Guide - See available NLog Targets and Layouts:https://nlog-project.org/config

Configuration

Programmatic Configuration

Advanced

Extending NLog

Clone this wiki locally


[8]ページ先頭

©2009-2025 Movatter.jp