You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
4.9 KiB
Plaintext

<?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"
autoReload="true"
throwExceptions="false"
internalLogLevel="off" internalLogFile="${basedir}/Logs/nlog-internal.log"
maxArchiveDays="7"
maxArchiveFiles="50">
7 months ago
<variable name="MicrosoftLevel" value="${level:lowercase=true:truncate=4:when=level==LogLevel.Info or level==LogLevel.Warn}${when:when=level==LogLevel.Error:inner=fail}${when:when=level==LogLevel.Fatal:inner=crit}${when:when=level==LogLevel.Debug:inner=dbug}${when:when=level==LogLevel.Trace:inner=trce}" />
<variable name="MicrosoftLayout" value="${MicrosoftLevel}: ${logger}[${event-properties:EventId_Id:whenEmpty=0}]${newline} ${message}${onexception:inner=${newline}${exception:format=tostring}}" />
7 months ago
<targets>
<!--archiveAboveSize="10240000"表示单个文件最大10M-->
<!--maxArchiveFiles="30"表示同一文件夹下最多留存30个日志文件超出将删除-->
<target name="console" xsi:type="ColoredConsole" async="true" layout="${MicrosoftLayout}" useDefaultRowHighlightingRules="false" >
<highlight-row condition="contains(message, 'Now listening')" foregroundColor="Yellow"/>
<highlight-word foregroundColor="DarkGreen" regex="^info" />
<highlight-word foregroundColor="Yellow" regex="^warn" />
<highlight-word foregroundColor="Black" backgroundColor="Red" regex="^fail" />
<highlight-word foregroundColor="White" backgroundColor="Red" regex="^crit" />
</target>
<target name="all" xsi:type="File" maxArchiveFiles="30" archiveAboveSize="10240000"
7 months ago
fileName="${basedir}/Logs/${shortdate}/All.log"
layout="${longdate} | ${level} | ${message} ${onexception:${exception:format=tostring} ${newline} ${stacktrace} ${newline}" />
<target name="error" xsi:type="File" maxArchiveFiles="30" archiveAboveSize="10240000"
7 months ago
fileName="${basedir}/Logs/${shortdate}/Error.log"
layout="${longdate} | ${level} | ${message} ${onexception:${exception:format=tostring} ${newline} ${stacktrace} ${newline}" />
<target name="big" xsi:type="AsyncWrapper">
<target xsi:type="File" maxArchiveFiles="30" archiveAboveSize="10240000"
7 months ago
fileName="${basedir}/Logs/${shortdate}/Big.log"
layout="${longdate} | ${level} | ${message}" />
</target>
7 months ago
9 months ago
<target name="info" xsi:type="File" maxArchiveFiles="30" archiveAboveSize="10240000"
7 months ago
fileName="${basedir}/Logs/${shortdate}/Info.log"
9 months ago
layout="${longdate} | ${level} | ${message} ${onexception:${exception:format=tostring} ${newline} ${stacktrace} ${newline}" />
<target name="database" xsi:type="Database"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=EFinance;Persist Security Info=True;User ID=sa;Password=123456;">
<commandText>
insert into syslogs
(Application,Levels,Operatingtime,Operatingaddress,Userid,Logger,Callsite,Requesturl,Referrerurl,Action,Message,Exception)
values
(@application,@levels,@operatingtime,@operatingaddress,@userid,@logger,@callSite,@requesturl,@referrerurl,@action,@message,@exception);
</commandText>
<parameter name="@application" layout="WebApi" />
<parameter name="@levels" layout="${level}" />
<parameter name="@operatingTime" layout="${date}" />
<parameter name="@operatingaddress" layout="${aspnet-Request-IP}" />
<parameter name="@userid" layout="1" />
<parameter name="@logger" layout="${logger}" />
<parameter name="@callSite" layout="${callsite}" />
<parameter name="@requesturl" layout="${aspnet-request-url}" />
<parameter name="@referrerurl" layout="${aspnet-request}" />
<parameter name="@action" layout="${aspnet-mvc-action}" />
<parameter name="@message" layout="${message}" />
<parameter name="@exception" layout="${exception:tostring}" />
</target>
</targets>
<rules>
<!-- 说明:
日志等级MIN TRACE,DEBUG,INFO,WARN,ERROR,FATAL MAX
final设置了final后当此路由被匹配到时不会再匹配此路由下面的路由。未匹配到此路由时才会继续匹配下一个路由
name="*":表示全部匹配 -->
<!-- 捕获全部日志,适用于调试阶段跟踪日志-->
<!--<logger name="*" minlevel="Trace" writeTo="all" />-->
<!-- 捕获日志到控制台 -->
<logger name="*" minlevel="INFO" writeTo="console" />
<!-- 只捕获异常 -->
<logger name="*" minlevel="ERROR" writeTo="error" />
<!-- 不记录微软的日志(异常的日志除外,因为会在上面的两个规则中记录) -->
<logger name="Microsoft.*" minlevel="Trace" final="true" />
<!-- 保存大数据量的日志,采用异步的方式 -->
<logger name="BigDataLogger" writeTo="big" final="true" />
<!-- 普通日志,记录到文件 -->
<logger name="*" minlevel="INFO" writeTo="info" />
<!-- 普通日志,记录到库 -->
<!--<logger name="*" minlevel="INFO" writeTo="database" />-->
</rules>
</nlog>