|
|
@@ -0,0 +1,73 @@
|
|
|
+<?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="true"
|
|
|
+ internalLogLevel="Info"
|
|
|
+ internalLogFile="${basedir}/NLog/${date:format=yyyyMM}/Bussiness.txt">
|
|
|
+ <extensions>
|
|
|
+ <add assembly="NLog.Web.AspNetCore"/>
|
|
|
+ </extensions>
|
|
|
+ <!-- 定义变量当前应用程序名称 -->
|
|
|
+ <variable name="AppName" value="Bussiness" />
|
|
|
+ <!-- 日志输出目标 -->
|
|
|
+ <targets>
|
|
|
+ <!--把日志输出到控制台 -->
|
|
|
+ <target xsi:type="Console" name="lifetimeConsole" layout="${level:truncate=4:tolower=true}: ${logger}[0]${newline} ${message}${exception:format=tostring}" />
|
|
|
+ <!-- 把日志记录到文件(通用) -->
|
|
|
+ <target xsi:type="File" name="allfile" fileName="${basedir}\..\Log\${date:format=yyyyMM}\${var:AppName}-all-${shortdate}.txt" encoding="UTF-8"
|
|
|
+ archiveFileName="${basedir}\..\Log\WMSAPI-all-${shortdate}.{#}.txt" archiveAboveSize="10485760"
|
|
|
+ layout="${longdate}|${event-properties:item=EventId_Id:whenEmpty=0}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
|
|
|
+ <!--把日志输出到数据库 -->
|
|
|
+ <target xsi:type="Database" name="database" dbProvider="MySqlConnector.MySqlConnection, MySqlConnector" connectionString="${configsetting:item=ConnectionStrings.DOPLog}">
|
|
|
+ <install-command ignoreFailures="true">
|
|
|
+ <text>
|
|
|
+ <!-- NOTE: call LogManager.Configuration.Install(new InstallationContext()); to execute this query. -->
|
|
|
+ CREATE TABLE IF NOT EXISTS `Sys_Log${date:format=yyyyMM}` (
|
|
|
+ `id` bigint NOT NULL AUTO_INCREMENT,
|
|
|
+ `createtime` datetime NOT NULL,
|
|
|
+ `appname` varchar(50) NOT NULL,
|
|
|
+ `modulename` varchar(50) NULL,
|
|
|
+ `level` varchar(50) NOT NULL,
|
|
|
+ `logger` varchar(1024) NULL DEFAULT NULL,
|
|
|
+ `msg` text NULL,
|
|
|
+ `userid` varchar(50) NULL DEFAULT NULL,
|
|
|
+ `url` varchar(1024) NULL DEFAULT NULL,
|
|
|
+ `ip` varchar(255) NULL DEFAULT NULL,
|
|
|
+ `tenantId` varchar(50) NULL,
|
|
|
+ PRIMARY KEY (`id`) USING BTREE
|
|
|
+ );
|
|
|
+ </text>
|
|
|
+ </install-command>
|
|
|
+ <commandText>
|
|
|
+ INSERT INTO `Sys_Log${date:format=yyyyMM}`(`createtime`, `appname`, `modulename`, `level`, `logger`, `msg`,`userid`, `url`, `ip`,`tenantId`) VALUES (@CreateTime, @AppName,@ModuleName, @Level, @Logger, @Msg, @UserId, @Url, @IP,@TenantId);
|
|
|
+ </commandText>
|
|
|
+ <parameter name="@CreateTime" layout="${longdate}" />
|
|
|
+ <parameter name="@AppName" layout="${var:AppName}" />
|
|
|
+ <parameter name="@ModuleName" layout="${event-context:item=ModuleName}" allowDbNull="true"/>
|
|
|
+ <parameter name="@Level" layout="${level}" />
|
|
|
+ <parameter name="@Logger" layout="${logger}" allowDbNull="true" />
|
|
|
+ <parameter name="@Msg" layout="${event-context:item=Msg}" allowDbNull="true" />
|
|
|
+ <parameter name="@UserId" layout="${aspnet-user-claim:userId}" allowDbNull="true" />
|
|
|
+ <parameter name="@Url" layout="${aspnet-request-url}" allowDbNull="true" />
|
|
|
+ <parameter name="@IP" layout="${aspnet-request-ip}" allowDbNull="true" />
|
|
|
+ <parameter name="@TenantId" layout="${event-context:item=TenantId}" allowDbNull="true" />
|
|
|
+ </target>
|
|
|
+ </targets>
|
|
|
+
|
|
|
+ <!-- 日志输出规则 -->
|
|
|
+ <rules>
|
|
|
+ <!--All logs, including from Microsoft-->
|
|
|
+ <!--<logger name="*" minlevel="Trace" writeTo="allfile" />-->
|
|
|
+
|
|
|
+ <!--Output hosting lifetime messages to console target for faster startup detection -->
|
|
|
+ <logger name="Microsoft.Hosting.Lifetime" minlevel="Debug" writeTo="allfile,database" final="true" />
|
|
|
+ <logger name="Microsoft.EntityFrameworkCore.Model.Validation" maxlevel="Error" writeTo="allfile,database" final="true" />
|
|
|
+
|
|
|
+ <!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) -->
|
|
|
+ <logger name="Microsoft.*" maxlevel="Info" final="true" />
|
|
|
+ <logger name="System.Net.Http.*" maxlevel="Info" final="true" />
|
|
|
+
|
|
|
+ <logger name="*" minlevel="Trace" writeTo="allfile,database" />
|
|
|
+ </rules>
|
|
|
+</nlog>
|