NLog 介紹及使用 - part2
在上一章介紹使用NuGet安裝 NLog後 會產生NLog.config 檔案,
此檔案是NLog的設定檔
<?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">
<!--
See http://nlog-project.org/wiki/Configuration_file
for information on customizing logging rules and outputs.
-->
<targets>
<!-- add your targets here -->
<!--
<target xsi:type="File" name="f" fileName="${basedir}/logs/${shortdate}.log"
layout="${longdate} ${uppercase:${level}} ${message}" />
-->
</targets>
<rules>
<!-- add your logging rules here -->
<!--
<logger name="*" minlevel="Trace" writeTo="f" />
-->
</rules>
</nlog>
主要介紹一下 targets跟rule這兩種設定.
<targets>
Targets are used to display, store, or pass log messages to another destination. There are two kinds of target;
those that receive and handle the messages, and those that buffer or route the messages to another target.
The second group are called 'wrapper' targets.
targets詳細介紹:targets
<rules>
Log routing rules are defined in the <rules /> section. It is a simple routing table,
where we define the list of targets that should be written to for each combination of source/logger name and log level.
Rules are processed starting with the first rule in the list. When a rule matches, log messages are directed to target(s) in that rule.
If a rule is marked as final, rules below it are not processed.
rules詳細介紹:rules
下一篇就實際作作看囉… ^_^