1.輸出到服務(wù)臺(tái)
<span style="font-size:18px;"><?xml version="1.0"encoding="utf-8" ?>
<nlogxmlns="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.xsdNLog.xsd"
? ? autoReload="true"
? ? throwExceptions="false"
? ? internalLogLevel="Off"internalLogFile="c:\temp\nlog-internal.log" >
? <!-- optional, add some variabeles
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
? <variable name="myvar" value="myvalue"/>
? <targets>
? ? ? <!--添加一個(gè)新條目讓日志輸出到控制臺(tái)中,并添加必要的輸出布局(layout)-->
? ? ? <target name="console" xsi:type="Console"layout="${longdate}|${level}|${message}"/>
? ? ? <!--說(shuō)明 xsi:type="Console"指定輸出到控制臺(tái)凛膏;layout指定輸出文件內(nèi)容的樣式${longdate}是日期(具體到毫秒)余蟹,${level}是日志的等級(jí)梅掠;${message}是具體要輸出的內(nèi)容刚盈。-->
? </targets>
? <rules>
? ? ? <!--添加必要的規(guī)則-->
? ? ? <logger name="*" writeTo="console"/>
? ? ? <!--我個(gè)人設(shè)置的規(guī)則是胎许,將所有記錄的信息輸出至控制臺(tái)-->
? </rules>
</nlog></span>
2.輸出到文件
<span style="font-size:18px;"><targets>
? ? ? <!--說(shuō)明 xsi:type="File"指定輸出到文件類型找前;fileName指定輸出文件的存放位置和文件名(可自定義),其中
? ? ${basedir}是程序所在的路徑调俘;
? ? ${shortdate}是日期(具體到日)伶棒。?
? ? layout指定輸出文件內(nèi)容的樣式?
? ? ${level}是日志的等級(jí)泉瞻;
? ? ${longdate}是日期(具體到毫秒),
? ? ${message}是具體要輸出的內(nèi)容苞冯。-->
? ? ? <target name="Info" xsi:type="File"fileName="${basedir}/log/test.${shortdate}.log"layout="${longdate} [${level}]: ${message}"/>
? </targets>
? <rules>
? ? ? <logger name="*" writeTo="Info"/>
? </rules></span>
3.輸出到數(shù)據(jù)庫(kù)
<span style="font-size:18px;"><?xml version="1.0"encoding="utf-8" ?>
<nlogxmlns="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.xsdNLog.xsd"
? ? autoReload="true"
? ? throwExceptions="false"
? ? internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<!-- optional, add some variabeles
https://github.com/nlog/NLog/wiki/Configuration-file#variables
-->
<variable name="myvar" value="myvalue"/>
<!--
? Seehttps://github.com/nlog/nlog/wiki/Configuration-file
? forinformation 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 possiblelayout renderers.
? -->
? <!--添加一個(gè)新條目讓日志輸出到控制臺(tái)中袖牙,并添加必要的輸出布局(layout)-->
? <!--<target name="console" xsi:type="Console"layout="${longdate}|${level}|${message}"/>-->
? <!--說(shuō)明 xsi:type="Console"指定輸出到控制臺(tái);layout指定輸出文件內(nèi)容的樣式${longdate}是日期(具體到毫秒)舅锄,${level}是日志的等級(jí)鞭达;${message}是具體要輸出的內(nèi)容。-->
? <!--Writing events to the a file with the date in the filename.-->
? <!--<target name="Info" xsi:type="File"fileName="${basedir}/log/test.${shortdate}.log"layout="${longdate} [${level}]:${message}"/>-->
? <target xsi:type="Database" name="database"connectionString="
? ? ? ? ? ? ? ? Data Source=(local);InitialCatalog=NLogtest;Persist Security Info=True;
? ? ? ? ? ? ? ? User ID=sa;Password=123456"commandText="insert into NLog_Log([CreateOn],[Origin],[LogLevel],[Message], [Exception],[StackTrace]) values (getdate(), @origin, @logLevel,@message,@exception, @stackTrace)">
? ? <!--日志來(lái)源-->
? ? <parameter name="@origin" layout="${callsite}"/>
? ? <!--日志等級(jí)-->
? ? <parameter name="@logLevel"layout="${level}"/>
? ? <!--日志消息-->
? ? <parameter name="@message"layout="${message}"/>
? ? <!--異常信息-->
? ? <parameter name="@exception"layout="${exception}" />
? ? <!--堆棧信息-->
? ? ? <parameter name="@stackTrace"layout="${stacktrace}"/>
? </target>
</targets>
<rules>
? <!-- add your logging rules here -->
? <!--<logger name="*" writeTo="Info"/>-->
? <logger name="*" minlevel="Debug"writeTo="database"/>
? <!--
? 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" />
? -->
</rules>
</nlog> </span>