.Net Core NLog 配置

2021-03-06 21:27

阅读:707

标签:sage   gray   case   trace   default   line   logs   nal   logger   

NLog.config

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"
      autoReload="true"
      throwExceptions="false"
      internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">

    variable name="logDirectory" value="${basedir}/logs"/>
    variable name="layoutVal" value="${date:format=HH\:mm\:ss}|${uppercase:${level}}|${callsite:fileName=True}${newline}${message}${newline}${exception}"/>
    variable name="consoleVal" value="${date:format=HH\:mm\:ss}|${pad:padding=5:inner=${level:uppercase=true}}|${message}"/>
    
    targets>
        target name="console" xsi:type="ColoredConsole" useDefaultRowHighlightingRules="false"
                layout="${consoleVal}" >
            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 xsi:type="File"
            name="logfile"
            fileName="${logDirectory}/${shortdate}_info.log"
            keepFileOpen="false"
            layout="${layoutVal}" />
        target xsi:type="File"
            name="warnfile"
            fileName="${logDirectory}/${shortdate}_warn.log"
            keepFileOpen="false"
            layout="${layoutVal}" />
        target xsi:type="File"
            name="errfile"
            fileName="${logDirectory}/${shortdate}_error.log"
            keepFileOpen="false"
            layout="${layoutVal}" />
        target xsi:type="File"
            name="debugfile"
            fileName="${logDirectory}/${shortdate}_debug.log"
            keepFileOpen="false"
            layout="${layoutVal}" />
    targets>
    
    rules>
        logger name="*" minlevel="Trace" writeTo="console"/>
        logger name="*" minlevel="Error" writeTo="errfile" />
        logger name="*" minlevel="Warn" writeTo="warnfile"/>
        logger name="*" minlevel="Info" writeTo="logfile"/>
        logger name="*" minlevel="Debug" writeTo="debugfile" />
    rules>
nlog>

 

.Net Core NLog 配置

标签:sage   gray   case   trace   default   line   logs   nal   logger   

原文地址:https://www.cnblogs.com/vipsoft/p/12893646.html


评论


亲,登录后才可以留言!