<?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"
      throwConfigExceptions="true"
      internalLogLevel="off"
      internalLogFile="nlog.txt">

  <!-- enable asp.net core layout renderers -->
  <extensions>
    <add assembly="NLog.Web.AspNetCore"/>
  </extensions>

  <targets>
    <target name="ApiTrace" xsi:type="Database" dbProvider="MySqlConnector.MySqlConnection, MySqlConnector"
    connectionString="Server=139.224.222.251;Database=smartVillage;UID=root;Password=wrnmb1001"
    commandText="INSERT INTO Sys_Logs (ID, Logger, Level, Host, Url , Method, Cookie, UserAgent, QueryString, Body , Message, CreateTime, IPAddress, Elapsed) VALUES (upper(uuid()), @Logger, @Level, @Host, @Url , @Method, @Cookie, @UserAgent, @QueryString, @Body , @Message, @CreateTime, @IPAddress, @Elapsed);">
      <parameter name="@Logger" layout="${logger}" />
      <parameter name="@Level" layout="${uppercase:${level}}" />
      <parameter name="@Host" layout="${aspnet-request-host}" />
      <parameter name="@Url" layout="${aspnet-request-url:IncludeScheme=false:IncludeHost=false}" />
      <parameter name="@Method" layout="${aspnet-request-method}" />
      <parameter name="@Cookie" layout="${aspnet-request-headers:HeaderNames=SYSTOKEN:ValuesOnly=true}" />
      <parameter name="@UserAgent" layout="${aspnet-request-useragent}" />
      <parameter name="@QueryString" layout="${aspnet-request-querystring:OutputFormat=JSON}" />
      <parameter name="@Body" layout="${event-properties:item=RequestBody}" />
      <parameter name="@Message" layout="${message}" />
      <parameter name="@CreateTime" layout="${longdate}" />
      <parameter name="@IPAddress" layout="${aspnet-request-ip}" />
      <parameter name="@Elapsed" layout="${event-properties:item=Elapsed}"/>
    </target>
    <target name="database" xsi:type="Database" dbProvider="MySqlConnector.MySqlConnection, MySqlConnector"
    connectionString="Server=139.224.222.251;Database=smartVillage;UID=root;Password=wrnmb1001"
    commandText="INSERT INTO Sys_Logs (ID, Logger, Level, Host, Url , Method, Cookie, UserAgent, QueryString, Body , Message, CreateTime, IPAddress, Elapsed) VALUES (upper(uuid()), @Logger, @Level, @Host, @Url , @Method, @Cookie, @UserAgent, @QueryString, @Body , @Message, @CreateTime, @IPAddress, 0);">
      <parameter name="@Logger" layout="${logger}" />
      <parameter name="@Level" layout="${uppercase:${level}}" />
      <parameter name="@Host" layout="${aspnet-request-host}" />
      <parameter name="@Url" layout="${aspnet-request-url:IncludeScheme=false:IncludeHost=false}" />
      <parameter name="@Method" layout="${aspnet-request-method}" />
      <parameter name="@Cookie" layout="${aspnet-request-headers:HeaderNames=SYSTOKEN:ValuesOnly=true}" />
      <parameter name="@UserAgent" layout="${aspnet-request-useragent}" />
      <parameter name="@QueryString" layout="${aspnet-request-querystring:OutputFormat=JSON}" />
      <parameter name="@Body" layout="${aspnet-request-posted-body}" />
      <parameter name="@Message" layout="${message}" />
      <parameter name="@CreateTime" layout="${longdate}" />
      <parameter name="@IPAddress" layout="${aspnet-request-ip}" />
    </target>
    <target name="error" xsi:type="File" layout="**************************************************************************************************************************${newline} 日志时间 ： ${longdate} ${newline} 日志来源 ： ${logger} ${newline} 日志级别 ： ${uppercase:${level}} ${newline} 日志内容 ： ${message}${newline}" fileName="${basedir}/Logs/${date:format=yyyyMM}/ERROR-${shortdate}.log" />
    <target name="debug" xsi:type="File" layout="**************************************************************************************************************************${newline} 日志时间 ： ${longdate} ${newline} 日志来源 ： ${logger} ${newline} 日志级别 ： ${uppercase:${level}} ${newline} 日志内容 ： ${message}${newline}" fileName="${basedir}/Logs/${date:format=yyyyMM}/DEBUG-${shortdate}.log" />
  </targets>
  <rules>
    <!-- add your logging rules here -->
    <!--
    Write all events with minimal level of Debug (So Debug, Info, Warn, Error and Fatal, but not Trace)  to "f"
    <logger name="*" minlevel="Debug" writeTo="f" />
    -->
    <!--Skip non-critical Microsoft logs and so log only own logs-->
    <logger name="Microsoft.*" maxlevel="Info" final="true" />
    <logger name="*" level="Trace" writeTo="ApiTrace" />
    <logger name="*" level="Info" writeTo="database" />
    <logger name="*" level="Warn" writeTo="database" />
    <logger name="*" level="Debug" writeTo="debug" />
    <logger name="*" level="Error" writeTo="error" />

  </rules>
</nlog>