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.
CoreShop/CoreCms.Net.Web.Admin/NLog.config

75 lines
4.6 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="NlogRecords.log">
<!--Nlog内部日志记录为Off关闭。除非纠错不可以设为Trace否则速度很慢起码Debug以上-->
<extensions>
<add assembly="NLog.Web.AspNetCore" />
</extensions>
<targets>
<!--通过数据库记录日志 配置
dbProvider请选择mysql或是sqlserver同时注意连接字符串,需要安装对应的sql数据提供程序
MYSQL:
dbProvider="MySql.Data.MySqlClient.MySqlConnection, MySql.Data"
connectionString="server=localhost;database=BaseMIS;user=root;password=123456"
MSSQL:
dbProvider="Microsoft.Data.SqlClient.SqlConnection, Microsoft.Data.SqlClient"
connectionString="Server=127.0.0.1;Database=BaseMIS;User ID=sa;Password=123456"
-->
<target name="log_database" xsi:type="Database" dbProvider="Microsoft.Data.SqlClient.SqlConnection, Microsoft.Data.SqlClient" connectionString="Server=127.0.0.1;uid=CoreShop;pwd=CoreShop;Database=CoreShop;MultipleActiveResultSets=true;pooling=true;min pool size=5;max pool size=32767;connect timeout=20;">
<commandText>
INSERT INTO SysNLogRecords
(LogDate,LogLevel,LogType,LogTitle,Logger,Message,MachineName,MachineIp,NetRequestMethod
,NetRequestUrl,NetUserIsauthenticated,NetUserAuthtype,NetUserIdentity,Exception)
VALUES
(@LogDate,@LogLevel,@LogType,@LogTitle,@Logger,@Message,@MachineName,@MachineIp,@NetRequestMethod
,@NetRequestUrl,@NetUserIsauthenticated,@NetUserAuthtype,@NetUserIdentity,@Exception);
</commandText>
<parameter name="@LogDate" layout="${date}" />
<parameter name="@LogLevel" layout="${level}" />
<parameter name="@LogType" layout="${event-properties:item=LogType}" />
<parameter name="@LogTitle" layout="${event-properties:item=LogTitle}" />
<parameter name="@Logger" layout="${logger}" />
<parameter name="@Message" layout="${message}" />
<parameter name="@MachineName" layout="${machinename}" />
<parameter name="@MachineIp" layout="${aspnet-request-ip}" />
<parameter name="@NetRequestMethod" layout="${aspnet-request-method}" />
<parameter name="@NetRequestUrl" layout="${aspnet-request-url}" />
<parameter name="@NetUserIsauthenticated" layout="${aspnet-user-isauthenticated}" />
<parameter name="@NetUserAuthtype" layout="${aspnet-user-authtype}" />
<parameter name="@NetUserIdentity" layout="${aspnet-user-identity}" />
<parameter name="@Exception" layout="${exception:tostring}" />
</target>
<target xsi:type="File" name="log_file" fileName="${basedir}/App_Data/nlog/${date:format=yyyy-MM}/${level}-${shortdate}.csv" encoding="utf-8">
<layout xsi:type="CSVLayout">
<column name="date" layout="${date}" />
<column name="LogTitle" layout="${event-properties:item=LogTitle}" />
<column name="message" layout="${message}" />
<column name="exception" layout="${exception:format=tostring}" />
<column name="machinename" layout="${machinename}" />
<column name="appdomain" layout="${appdomain}" />
<column name="assembly-version" layout=" ${assembly-version}" />
<column name="basedir" layout="${basedir}" />
<column name="callsite" layout="${callsite}" />
<column name="counter" layout="${counter}" />
<column name="nlogdir" layout="${nlogdir}" />
<column name="processid" layout="${processid}" />
<column name="processname" layout="${processname}" />
<column name="specialfolder" layout="${specialfolder}" />
<column name="stacktrace" layout="${stacktrace}" />
<column name="longdate" layout="${longdate}" />
<column name="event-properties" layout="${event-properties:item=EventId_Id}" />
<column name="uppercase" layout="${uppercase:${level}}" />
<column name="logger" layout="${logger}" />
<column name="url" layout="${aspnet-request-url}" />
<column name="action" layout="${aspnet-mvc-action}" />
</layout>
</target>
</targets>
<rules>
<!--跳过所有级别的Microsoft组件的日志记录-->
<logger name="Microsoft.*" final="true" />
<!-- BlackHole without writeTo -->
<!--只通过数据库记录日志如果给了name名字cs里用日志记录的时候取logger需要把name当做参数-->
<logger name="logdb" writeTo="log_database" />
<logger name="logfile" writeTo="log_file" />
</rules>
</nlog>