|
|
@@ -1,110 +1,33 @@
|
|
|
<?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}/Procurement.txt">
|
|
|
- <extensions>
|
|
|
- <add assembly="NLog.Web.AspNetCore"/>
|
|
|
- </extensions>
|
|
|
- <!-- 定义变量当前应用程序名称 -->
|
|
|
- <variable name="AppName" value="Procurement" />
|
|
|
- <!-- 日志输出目标 -->
|
|
|
- <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="${gdc:item=appbasepath}\logs\nlog-${shortdate}.log" encoding="UTF-8"
|
|
|
- archiveFileName="${gdc:item=appbasepath}\logs\nlog-${shortdate}.{#}.log" 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>-->
|
|
|
- <target xsi:type="Database" name="database" dbProvider="Microsoft.Data.SqlClient.SqlConnection, Microsoft.Data.SqlClient" connectionString="${configsetting:item=ConnectionStrings.DOPLog}">
|
|
|
- <install-command ignoreFailures="true">
|
|
|
- <text>
|
|
|
- <!-- NOTE: call LogManager.Configuration.Install(new InstallationContext()); to execute this query. -->
|
|
|
- if not exists (select * from sysobjects where id = object_id('dbo.Sys_Log${date:format=yyyyMM}')
|
|
|
- and OBJECTPROPERTY(id, 'IsUserTable') = 1)
|
|
|
- create table dbo.Sys_Log${date:format=yyyyMM}
|
|
|
- (
|
|
|
- id bigint identity(1,1) not null,
|
|
|
- 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,
|
|
|
- CONSTRAINT [PK_dbo.Sys_Log${date:format=yyyyMM}] PRIMARY KEY CLUSTERED ([id] ASC) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
|
|
- )
|
|
|
- </text>
|
|
|
- </install-command>
|
|
|
- <commandText>
|
|
|
- INSERT INTO dbo.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="${date}" />
|
|
|
- <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>
|
|
|
+ autoReload="true">
|
|
|
+ <targets>
|
|
|
+ <target xsi:type="Null" name="blackhole" />
|
|
|
+ <target name="loginfo" xsi:type="File" fileName="logs/${shortdate}.log" />
|
|
|
+
|
|
|
+ <target name="db"
|
|
|
+ xsi:type="Database"
|
|
|
+ connectionString="${var:NLOG_CONNECTION_STRING}"
|
|
|
+ commandType="StoredProcedure"
|
|
|
+ commandText="[dbo].[pr_SFM_SaveWebApiLog]">
|
|
|
+ <parameter name="@traceId" layout="${aspnet-TraceIdentifier}" />
|
|
|
+ <parameter name="@eventId" layout="${event-properties:EventId}" />
|
|
|
+ <parameter name="@type" layout="${event-context:item=Type}" />
|
|
|
+ <parameter name="@action" layout="${event-context:item=Action}" />
|
|
|
+ <parameter name="@application" layout="Procurement" />
|
|
|
+ <parameter name="@level" layout="${level}" />
|
|
|
+ <parameter name="@category" layout="${logger}" />
|
|
|
+ <parameter name="@message" layout="${message}" />
|
|
|
+ <parameter name="@properties" layout="${all-event-properties:separator=|}" />
|
|
|
+ <parameter name="@exception" layout="${exception:tostring}" />
|
|
|
+ <parameter name="@clientIP" layout="${aspnet-request-ip}" />
|
|
|
+ </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>
|
|
|
+ <rules>
|
|
|
+ <logger name="Microsoft.EntityFrameworkCore.Infrastructure" minlevel="Info" writeTo="blackhole" final="true" />
|
|
|
+ <logger name="Procurement.Core.NLogHelper" minlevel="Info" writeTo="db"/>
|
|
|
+ <logger name="*" minlevel="Info" writeTo="loginfo" />
|
|
|
+ </rules>
|
|
|
</nlog>
|