标签:var 子节点 简单的 bug mat conf rac 日志 file
版权声明:本文为博主原创文章,未经博主允许不得转载。
NLog是一款拥有丰富的途径选择和管理能力的可用于.net、Silverlight和Windows Phone的免费开源框架.它可以将任何.net语言产生的调试信息转化为上下文信息(包括日期和时间,严重程度,进程,线程,环境信息),根据你喜好的形式发送到一个或者多个目标存储。那么,我们如何在一个应用程序上配置使用NLog,将日志输出到控制台和文件?
首先,打开VS2012创建一个控制台应用程序,添加NLog.dll引用。
接下来,开始配置NLog配置文件,NLog配置文件支持两种方式:
1)是将配置写到应用程序的配置文件(通常是applicationName.exe.config)或者Web.config文件中;
2)独配置到一个文件,通常是NLog.config
这里采用第一种方法,首先我们需要在配置文件中增加如下形式的配置
<configuration> <configSections> <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/> </configSections> <nlog> </nlog></configuration><targets /> –定义日志记录输出的目标位置,可以配置为输出到控制台,文件,数据库,事件日志等等<rules /> –定义日志输出路径规则<extensions /> –定义从某个*.dll获取Nlog扩展<include />– 包含外部的配置文件<variable /> – 设置配置变量的值<?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/> </configSections> <nlog autoReload="true" internalLogLevel="Trace" internalLogFile="logs/internalLog.txt"> <targets> <target name="t1" type="File" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate} ${callsite} ${level}: ${message} ${event-context:item=exception} ${stacktrace} ${event-context:item=stacktrace}"/> <target name="t2" type="Console" layout="${date:format=yyyyMMddHHmmss} ${callsite} ${level} ${message}"/> </targets> <rules> <logger name="NLogConsoleExample" minlevel="Debug" maxlevel="Error" writeTo="t1,t2" /> </rules> </nlog> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup></configuration>标签:var 子节点 简单的 bug mat conf rac 日志 file
原文地址:http://www.cnblogs.com/Li-yuan/p/7522121.html