<?xml version="1.0" encoding="utf-8"?>
<!-- 配置文档 https://nlog-project.org/config -->
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" autoReload="true" internalLogLevel="Info">
  <!-- 启用.net core的核心布局渲染器 -->
  <extensions>
    <add assembly="NLog.Web.AspNetCore" />
  </extensions>
  <!-- 写入日志的目标配置 archiveAboveSize="102400" maxArchiveDays="60" -->
  <targets>
    <!-- 调试  -->
    <target xsi:type="File" name="debug" fileName="../logs/debug-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
    <!-- 警告  -->
    <target xsi:type="File" name="warn" fileName="../logs/warn-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
    <!-- 错误  -->
    <target xsi:type="File" name="error" fileName="../logs/error-${shortdate}.log" layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}" />
    <!-- 控制台  -->
    <target xsi:type="Console" name="console" layout="${message}" />
	<!-- 数据库  https://github.com/NLog/NLog/wiki/Database-target -->
	<target name="db" xsi:type="Database" connectionString="Data Source=|DataDirectory|\\admindb.db; Pooling=true;Min Pool Size=1" dbProvider="System.Data.SQLite.SQLiteConnection, System.Data.SQLite">
		<commandText>
			INSERT INTO "ad_log"("Id", "Logged", "Level", "Message", "Logger", "Properties", "Callsite", "Exception") VALUES(@Id, @Logged, @Level, @Message, @Logger, @Properties, @Callsite, @Exception)
		</commandText>
		<!-- 自定义主键  -->
		<parameter name="@Id" layout="${event-properties:id}" />
		<parameter name="@Logged" layout="${date}" />
		<parameter name="@Level" layout="${level}" />
		<parameter name="@Message" layout="${message}" />
		<parameter name="@Logger" layout="${logger}" />
		<!-- 自定义属性  -->
		<parameter name="@properties" layout="${all-event-properties:separator=|}" />
		<parameter name="@Callsite" layout="${callsite}" />
		<parameter name="@Exception" layout="${exception:tostring}" />
	</target>
  </targets>
  <!-- 映射规则 -->
  <rules>
	<!--跳过不重要的微软日志-->
	<logger name="Microsoft.*" maxlevel="Info" final="true" />
	<!-- 数据库  -->
	<logger name="db" writeTo="db" />
    <!-- 调试  -->
    <logger name="*" minlevel="Trace" maxlevel="Debug" writeTo="debug" />
    <logger name="*" minlevel="Trace" writeTo="console" />
    <!-- 警告  -->
    <logger name="*" minlevel="Info" maxlevel="Warn" writeTo="warn" />
    <!-- 错误  -->
    <logger name="*" minlevel="Error" maxlevel="Fatal" writeTo="error" />
  </rules>
</nlog>