[.Net Framework][Windows應用程式] NLog突然沒記到DB
開發的Windows應用程式,應用程式有正常作業,但突然NLog沒有寫到DB,
DB一直查不到歷程,但應用程式關掉重開後,突然先前的歷程都跑出來的,
不清楚怎麼一回事。
補上NLog.config
<?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="nlog-internal.log">
<targets async="true">
<target xsi:type="Database"
name="database"
connectionString="data source=xxx;initial catalog=xxx;user id=xxx;password=xxx;MultipleActiveResultSets=True;"
dbProvider="mssql"
commandText="INSERT INTO NLOG_AP(CreateDate,Origin,LogLevel,[Message],StackTrace,Exception) VALUES (@CreateDate,@Origin,@LogLevel,@Message,@StackTrace,@Exception)">
<parameter name="@CreateDate" layout="${date:format=yyyy\-MM\-dd HH\:mm\:ss\:fff}"/>
<!--日誌發生時間-->
<parameter name="@Origin" layout="${callsite}"/>
<!--日誌來源-->
<parameter name="@LogLevel" layout="${level}"/>
<!--日誌等級-->
<parameter name="@Message" layout="${message}"/>
<!--日誌資訊-->
<parameter name="@StackTrace" layout="${stacktrace}"/>
<!--堆疊資訊-->
<parameter name="@Exception" layout="${exception:format=ToString}"/>
<!--詳細資訊-->
</target>
<target xsi:type="Database"
name="database2"
connectionString="data source=xxx;initial catalog=xxx;user id=xxx;password=xxx;MultipleActiveResultSets=True;"
dbProvider="mssql"
commandText="INSERT INTO NLOG2_AP(CreateDate,Origin,LogLevel,[Message],StackTrace,Exception) VALUES (@CreateDate,@Origin,@LogLevel,@Message,@StackTrace,@Exception)">
<parameter name="@CreateDate" layout="${date:format=yyyy\-MM\-dd HH\:mm\:ss\:fff}"/>
<!--日誌發生時間-->
<parameter name="@Origin" layout="${callsite}"/>
<!--日誌來源-->
<parameter name="@LogLevel" layout="${level}"/>
<!--日誌等級-->
<parameter name="@Message" layout="${message}"/>
<!--日誌資訊-->
<parameter name="@StackTrace" layout="${stacktrace}"/>
<!--堆疊資訊-->
<parameter name="@Exception" layout="${exception:format=ToString}"/>
<!--詳細資訊-->
</target>
<target name="file" xsi:type="File"
fileName="${basedir}/Logs/${date:format=yyyy-MM}/${date:format=yyyy-MM-dd}.log"
layout="${date:format=yyyy\-MM\-dd HH\:mm\:ss.ffff}|${level}|${message}|堆疊: ${stacktrace}|詳細錯誤: ${exception}" />
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="database" />
<logger name="*" minlevel="Error" writeTo="database2" />
<logger name="*" minlevel="Error" writeTo="file" />
</rules>
</nlog>