Zum Hauptinhalt springen

NLog.config template

<?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"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="${basedir}\App_Data\Logs\nlog-internal.log" >

<extensions>
<!-- adds the ${abp-user-id} and ${abp-tenant-id} parameters-->
<add assembly="Abp.Logging.NLog"/>
<!-- logs to azure application insights -->
<add assembly="Microsoft.ApplicationInsights.NLogTarget" />
</extensions>

<!-- optional, add some variabeles
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="logDir" value="${basedir}/App_Data/Logs"/>
<variable name="logArchiveDir" value="${basedir}/App_Data/Logs/Archives"/>

<!--
See https://github.com/nlog/nlog/wiki/Configuration-file
for information on customizing logging rules and outputs.
-->
<targets>

<!--
add your targets here
See https://github.com/nlog/NLog/wiki/Targets for possible targets.
See https://github.com/nlog/NLog/wiki/Layout-Renderers for the possible layout renderers.
-->

<!--
Writing events to the a file with the date in the filename.
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
<target name="Sql" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target xsi:type="File"
fileName="${logDir}/${shortdate}_sql_vm01.log"
layout="${longdate}|log:${logger}|thr:${threadid}|${uppercase:${level}}|usr:${abp-user-id}|ten:${abp-tenant-id}|${message}"
keepFileOpen="false"
archiveFileName="${logArchiveDir}/{#}_sql_vm01.txt"
archiveNumbering="DateAndSequence"
archiveAboveSize="5000000"
archiveEvery="Day"
archiveDateFormat="yyyyMMdd"
maxArchiveFiles="7"
concurrentWrites="true"/>
</target>

<target xsi:type="Null" name="Disabled" formatMessage="false" layout="" />

<target name="Synchronization" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target xsi:type="File"
fileName="${logDir}/${shortdate}_sync.log"
layout="${longdate}|log:${logger}|thr:${threadid}|${uppercase:${level}}|usr:${abp-user-id}|ten:${abp-tenant-id}|${message}"
keepFileOpen="false"
archiveFileName="${logArchiveDir}/{#}_sync.txt"
archiveNumbering="DateAndSequence"
archiveAboveSize="5000000"
archiveEvery="Day"
archiveDateFormat="yyyyMMdd"
maxArchiveFiles="7"
concurrentWrites="true"/>
</target>
<target name="SynchronizationAlerts" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target xsi:type="Mail"
to="support@opti-q.com"
from="noreply@testportal.opti-q.com"
useSystemNetMailSettings="true"
layout="${longdate} ${uppercase:${level}} ${callsite:className=true:includeSourcePath=true:methodName=true} ${message}${newline}"
/>
</target>


<target name="Jobs" xsi:type="AsyncWrapper" queueLimit="500" overflowAction="Block">
<target xsi:type="File"
fileName="${logDir}/${shortdate}_jobs_vm01.log"
layout="${longdate}|log:${logger}|thr:${threadid}|${uppercase:${level}}|usr:${abp-user-id}|ten:${abp-tenant-id}|${message}"
keepFileOpen="false"
archiveFileName="${logArchiveDir}/{#}_jobs_vm01.txt"
archiveNumbering="DateAndSequence"
archiveAboveSize="5000000"
archiveEvery="Day"
archiveDateFormat="yyyyMMdd"
maxArchiveFiles="7"
concurrentWrites="true"/>
</target>

<!-- Note:
To avoid spamming, at least "buffersize" messages need to be present before a mail is sent. Default is 300
If the buffer is not filled within the "flushtimeout" (5minutes = 300000 milliseconds by default) the mail is sent nevertheless. -->
<target name="JobAlerts"
xsi:type="BufferingWrapper"
slidingTimeout="true"
bufferSize="300"
flushTimeout="300000">
<target xsi:type="Mail"
to="support@opti-q.com"
cc=""
from="noreply@testportal.opti-q.com"
useSystemNetMailSettings="true"
layout="${longdate} ${uppercase:${level}} ${callsite:className=true:includeSourcePath=true:methodName=true} ${message}${newline}"
/>
</target>

<target name="Trace" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target xsi:type="File"
fileName="${logDir}/${shortdate}_trace_vm01.log"
layout="${longdate}|log:${logger}|thr:${threadid}|${uppercase:${level}}|usr:${abp-user-id}|ten:${abp-tenant-id}|${message}"
keepFileOpen="false"
archiveFileName="${logArchiveDir}/{#}_trace_vm01.txt"
archiveNumbering="DateAndSequence"
archiveAboveSize="5000000"
archiveEvery="Day"
archiveDateFormat="yyyyMMdd"
maxArchiveFiles="7"
concurrentWrites="true"/>
</target>

<target name="Error" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">
<target xsi:type="File"
fileName="${logDir}/${shortdate}_error_vm01.log"
layout="${longdate}|log:${logger}|thr:${threadid}|${uppercase:${level}}|usr:${abp-user-id}|ten:${abp-tenant-id}|${message}
${exception:format=toString,Data:maxInnerExceptionLevel=10}"
keepFileOpen="false"
archiveFileName="${logArchiveDir}/{#}_error_vm01.txt"
archiveNumbering="DateAndSequence"
archiveAboveSize="5000000"
archiveEvery="Day"
archiveDateFormat="yyyyMMdd"
maxArchiveFiles="7"
concurrentWrites="true" />
</target>

<!-- do NOT comment this out as Opti-Q otherwise cannot guarantee seamless support! -->
<target name="aiTarget" xsi:type="ApplicationInsightsTarget" />
</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" />
-->

<logger name="Sql*" minlevel="Debug" writeTo="Disabled" final="true" />
<!--<logger name="Sql*" minlevel="Debug" writeTo="Sql" final="true" />-->
<!--<logger name="Hangfire*" minlevel="Warn" writeTo="JobAlerts" />-->
<logger name="Hangfire*" minlevel="Error" writeTo="Jobs" final="true" />
<logger name="Hangfire*" minlevel="Debug" writeTo="Disabled" final="true" />
<logger name="Synchronization*" minlevel="Debug" writeTo="SynchronizationAlerts" final="false" />
<logger name="Synchronization*" minlevel="Debug" writeTo="Synchronization" final="true" />
<logger name="*" minlevel="Warn" writeTo="aiTarget" />
<logger name="*" minlevel="Error" writeTo="Error" />
<logger name="*" minlevel="Debug" writeTo="Disabled" />

</rules>

</nlog>