Nlog配置文件
Posted 遗失的似曾相识
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Nlog配置文件相关的知识,希望对你有一定的参考价值。
<?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">
<!-- optional, add some variables
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>
<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->
<!--参考资料:https://github.com/nlog/nlog/wiki/-->
<!-- 定义输出模板:
type="File":这个记录方式为文件类型
fileName="${logDirectory}/All.log":表示输出到文件All.log中
layout="...":输出文件中错误的显示格式
${logDirectory}:为上述定义的路径
${longdate}:输出长日期 yyyy-MM-dd HH:mm:ss.ffff(例:2013-01-31 14:49:21.2120)
${level}:错误等级(由低到高为Trace,Debug,Info,Warn,Error,Fatal)
${newline}:输出 新的一行
${stacktrace}:输出 堆栈信息
${callsite:className=True:fileName=True:includeSourcePath=True:methodName=True}:输出 命名空间.类名.方法名(文件路径:行号)
${message}:输出错误信息-->
<target name="logFileDebug"
xsi:type="File"
fileName="${basedir}/logs/Debug${shortdate}.log"
layout="${date:format=yyyy-MM-dd HH\\:mm\\:ss.fff}|${uppercase:${level}}|位置${callsite:skipFrames=1}|行号${callsite-linenumber:skipFrames=1}|${message}"/>
<target name="logFileInfo"
xsi:type="File"
fileName="${basedir}/logs/Info${shortdate}.log"
layout="${date:format=yyyy-MM-dd HH\\:mm\\:ss.fff}|${uppercase:${level}}|位置${callsite:skipFrames=1}|行号${callsite-linenumber:skipFrames=1}|${message}"/>
<target name="logFileError"
xsi:type="File"
fileName="${basedir}/logs/Error${shortdate}.log"
layout="${date:format=yyyy-MM-dd HH\\:mm\\:ss.fff}|${uppercase:${level}}|位置${callsite:skipFrames=1}|行号${callsite-linenumber:skipFrames=1}|${message}"/>
<!--useDefaultRowHighlightingRules - 指示是否使用默认行高亮规则-->
<!--彩色控制台-ColoredConsole;控制台-Console-->
<target name="logCslDebug"
xsi:type="ColoredConsole"
useDefaultRowHighlightingRules="false"
layout="${date:format=yyyy-MM-dd HH\\:mm\\:ss.fff}|${uppercase:${level}}|位置${callsite:skipFrames=1}|行号${callsite-linenumber:skipFrames=1}|${message}">
<!--NoChange-不要改变颜色; DarkCyan - 深青色;White-白色 ;Red-红色; 黄色-yellow;灰色-Gray;DarkGray-深灰色-->
<highlight-row condition="level == LogLevel.Debug" foregroundColor="Gray" />
<highlight-row condition="level == LogLevel.Info" foregroundColor="white" />
<highlight-row condition="level == LogLevel.Warn" foregroundColor="Yellow" />
<highlight-row condition="level == LogLevel.Error" foregroundColor="red" />
</target>
<target name="logCslInfo"
xsi:type="Console"
layout="${date:format=yyyy-MM-dd HH\\:mm\\:ss.fff}|${uppercase:${level}}|位置${callsite:skipFrames=1}|行号${callsite-linenumber:skipFrames=1}|${message}"/>
<!--
<target name="database" xsi:type="Database" keepConnection="false" useTransactions="true"
dbProvider="System.Data.OracleClient.OracleConnection,System.Data.OracleClient, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
connectionString="User ID=lwtb_lppz;Password=lwtb_lppz;Data Source=(DESCRIPTION = (ADDRESS_LIST= (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.22)(PORT = 1521))) (CONNECT_DATA = (SERVICE_NAME = ORCLFLOOR2)))"
commandText="insert into sys_log(APPNAME,MODULENAME,PROCNAME,OPERATIONTYPE,LOGGER,LOGMESSAGE,IP,LONGDATE,USERNAME,LOGLEVEL) values(:APPNAME,:MODULENAME,:PROCNAME,:OPERATIONTYPE,:LOGGER,:LOGMESSAGE,:IP,:TIME_STAMP,:USERNAME,:LOGLEVEL)">
<parameter name="APPNAME" layout="${event-context:item=APPNAME}" />
<parameter name="MODULENAME" layout="${event-context:item=MODULENAME}" />
<parameter name="PROCNAME" layout="${event-context:item=PROCNAME}" />
<parameter name="OPERATIONTYPE" layout="${event-context:item=OPERATIONTYPE}" />
<parameter name="LOGGER" layout="${event-context:item=LOGGER}" />
<parameter name="LOGMESSAGE" layout="${event-context:item=LOGMESSAGE}" />
<parameter name="IP" layout="${event-context:item=IP}" />
<parameter name="TIME_STAMP" layout="${longdate}" />
<parameter name="USERNAME" layout="${event-context:item=USERNAME}" />
<parameter name="LOGLEVEL" layout="${level:uppercase=true}" />
</target>
-->
</targets>
<rules>
<!-- add your logging rules here -->
<!--TRACE,DEBUG,INFO,WARN,ERROR,FATAL-->
<!--1.从左到右等级依次升高,高等级日志会记入低等级日志文件中,低等级不会记入高等级-->
<!--2.ERROR日志会记入logFile,errorFile两个文件中-->
<!--3.DEBUG日志只会记到logFile文件中,不会记入errorFile文件中-->
<logger name="*" writeTo="logFileDebug" minlevel="Debug"/>
<logger name="*" writeTo="logFileInfo" minlevel="Info"/>
<logger name="*" writeTo="logFileError" minlevel="Error" />
<logger name="*" writeTo="logCslDebug" minlevel="Debug" />
<!--<logger name="*" writeTo="logCslInfo" minlevel="Info" />-->
</rules>
</nlog>
以上是关于Nlog配置文件的主要内容,如果未能解决你的问题,请参考以下文章