forked from kylelib/NLog-MDLC-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNLog.config
More file actions
43 lines (36 loc) · 2.06 KB
/
Copy pathNLog.config
File metadata and controls
43 lines (36 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?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="c:\temp\nlog-internal.log" >
<!-- Tells troubleshooter who logged the entry -->
<variable name="appName" value="NLogCustomLoggingContext"/>
<targets>
<!--********** Sample logging to file using Mapped Diagnostics Logging (MDLC) item **********-->
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${mdlc:item=trackingId} ${uppercase:${level}} ${message}" />
<target xsi:type="Database" name="db">
<dbProvider>System.Data.SqlClient</dbProvider>
<connectionString>Data Source=(LocalDb)\v11.0;Initial Catalog=ApplicationLog;Integrated Security=True</connectionString>
<commandText>
INSERT INTO Logging(Application, Level, Logger, Message, MachineName, UserName, Thread, Exception, TrackingId) VALUES (@appName, @level, @logger, @message, @machinename, @user_name, @threadid, @log_exception, @trackingId);
</commandText>
<parameter name="@appName" layout="${appName}" />
<parameter name="@level" layout="${level}" />
<parameter name="@logger" layout="${logger}" />
<parameter name="@message" layout="${message}" />
<parameter name="@machinename" layout="${machinename}" />
<parameter name="@user_name" layout="${windows-identity:domain=true}" />
<parameter name="@threadid" layout="${threadid}" />
<parameter name="@log_exception" layout="${exception:format=tostring}" />
<!--********** The Mapped Diagnostics Logical Context MDLC item we want logged **********-->
<parameter name="@trackingId" layout="${mdlc:item=trackingId}" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Debug" writeTo="f" />
<logger name="*" minlevel="Debug" writeTo="db" />
</rules>
</nlog>