首页 > 代码库 > Nlog配置实例

Nlog配置实例

 

彩色Console target

<?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">    <targets>        <target name="coloredConsole" xsi:type="ColoredConsole" useDefaultRowHighlightingRules="false"        layout="${longdate}|${pad:padding=5:inner=${level:uppercase=true}}|${message}" >            <highlight-row condition="level == LogLevel.Debug" foregroundColor="DarkGray" />            <highlight-row condition="level == LogLevel.Info" foregroundColor="Gray" />            <highlight-row condition="level == LogLevel.Warn" foregroundColor="Yellow" />            <highlight-row condition="level == LogLevel.Error" foregroundColor="Red" />            <highlight-row condition="level == LogLevel.Fatal" foregroundColor="Red" backgroundColor="White" />        </target>        <target name="infoFile" xsi:type="File"            layout="${longdate} ${pad:padding=5:inner=${level:uppercase=true}} ${logger} ${message}"            fileName="${basedir}/logs/info.log" keepFileOpen="false" encoding="iso-8859-2" />        <target name="errorFile" xsi:type="File"            layout="${longdate} ${pad:padding=5:inner=${level:uppercase=true}} ${logger} ${message}"            fileName="${basedir}/logs/error.log" keepFileOpen="false" encoding="iso-8859-2" />    </targets>    <rules>        <logger name="*" minlevel="Debug" writeTo="coloredConsole" />        <logger name="*" minlevel="Debug" maxlevel="Info" writeTo="infoFile" />        <logger name="*" minlevel="Warn" maxlevel="Fatal" writeTo="errorFile" />    </rules></nlog>

 

Nlog Configuration file

Nlog配置实例