C#Nlog配置文件 万能模板 输出到控制台及文件
2016-07-28 09:22
351 查看
项目中经常用到的配置文件模板,在这里做一下记录,也方便给大家查看,直接上代码:
已用过很多次了。
具体解释,请参考其他文章,网上已经写的很详尽了。
直接拿去使用,不谢:
<?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">
<targets>
<target name="console" xsi:type="ColoredConsole"
layout= "$[${date:format=yyyy-MM-dd HH\:mm\:ss}] [${uppercase:${level}}] [${logger}] [${callsite}]: ${message}"/>
<target name="file" xsi:type="File"
fileName="${basedir}/Logs/${date:format=yyyy}/${date:format=MM}/${shortdate}.log"
layout="[${date:format=yyyy-MM-dd HH\:mm\:ss}] [${uppercase:${level}}] [${callsite}]: ${message}"
keepFileOpen="false"
encoding="iso-8859-2" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="console"/>
<logger name="*" minlevel="Trace" writeTo="file" />
</rules>
</nlog>
说明:LOGS输出在,项目所在文件夹->启动项文件夹->Bin->Debug->LOGS
已用过很多次了。
具体解释,请参考其他文章,网上已经写的很详尽了。
直接拿去使用,不谢:
<?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">
<targets>
<target name="console" xsi:type="ColoredConsole"
layout= "$[${date:format=yyyy-MM-dd HH\:mm\:ss}] [${uppercase:${level}}] [${logger}] [${callsite}]: ${message}"/>
<target name="file" xsi:type="File"
fileName="${basedir}/Logs/${date:format=yyyy}/${date:format=MM}/${shortdate}.log"
layout="[${date:format=yyyy-MM-dd HH\:mm\:ss}] [${uppercase:${level}}] [${callsite}]: ${message}"
keepFileOpen="false"
encoding="iso-8859-2" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="console"/>
<logger name="*" minlevel="Trace" writeTo="file" />
</rules>
</nlog>
说明:LOGS输出在,项目所在文件夹->启动项文件夹->Bin->Debug->LOGS
相关文章推荐
- c#调用COM组件
- C#实现把指定数据写入串口
- C#动态创建button的方法
- C#中抽象方法与虚拟方法的区别
- c#中虚函数的相关使用方法
- C#实现给图片加水印的方法
- C#使用加边法计算行列式的值
- C#实现多线程的同步方法实例分析
- C#中尾递归的使用、优化及编译器优化
- C#中的delegate委托类型基本学习教程
- C#实现子窗体与父窗体通信方法实例总结
- C#通用邮件发送类分享
- 举例讲解C#中自动实现的属性
- C#中this的用法集锦
- C#数据结构之顺序表(SeqList)实例详解
- C#.NET获取拨号连接的宽带连接方法
- C#异步绑定数据实现方法
- C#实现AddRange为数组添加多个元素的方法
- C#中Equality和Identity浅析
- C#比较二个数组并找出相同或不同元素的方法