| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?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>
- <!-- 日志输出规则 -->
- <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>
|