Nlog配置实例

Posted Look Into Coding

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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配置实例的主要内容,如果未能解决你的问题,请参考以下文章

如何为 XSLT 代码片段配置 CruiseControl 的 C# 版本?

solr分布式索引实战分片配置读取:工具类configUtil.java,读取配置代码片段,配置实例

日志学习系列——NLog实例

拓展 NLog 优雅的输送日志到 Logstash

拓展 NLog 优雅的输送日志到 Logstash

NLog学习笔记二:深入学习