| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- <?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="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="Info" writeTo="lifetimeConsole,database" final="true" />
- <logger name="Microsoft.EntityFrameworkCore.Model.Validation" maxlevel="Error" 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="lifetimeConsole,database" />
- </rules>
- </nlog>
|