怎么卸载软件圆圆打字高手3这个软件

&>&&>&&>&&>&NLog自定义数据详细配置实例
NLog自定义数据详细配置实例
上传大小:3KB
开源日志库NLog的详细配置实例
包括写入文件、DB、自定数据表、异步等配置
综合评分:3.8(6位用户评分)
所需积分:2
下载次数:45
审核通过送C币
创建者:hslh99
创建者:djk8888
创建者:hubing
课程推荐相关知识库
上传者其他资源上传者专辑
开发技术热门标签
VIP会员动态
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
android服务器底层网络模块的设计方法
所需积分:0
剩余积分:720
您当前C币:0
可兑换下载积分:0
兑换下载分:
兑换失败,您当前C币不够,请先充值C币
消耗C币:0
你当前的下载分为234。
NLog自定义数据详细配置实例
会员到期时间:
剩余下载次数:
你还不是VIP会员
开通VIP会员权限,免积分下载
你下载资源过于频繁,请输入验证码
您因违反CSDN下载频道规则而被锁定帐户,如有疑问,请联络:!
若举报审核通过,可奖励20下载分
被举报人:
举报的资源分:
请选择类型
资源无法下载
资源无法使用
标题与实际内容不符
含有危害国家安全内容
含有反动色情等内容
含广告内容
版权问题,侵犯个人或公司的版权
*详细原因:NLog 的源代码托管在Github 上,一般的人直接使用NuGet就可以了。
这里我们选择安装NLog.Config。当然最方便的还是直接使用命令行:
Install-Package NLog.Config
Logger是最常用的类,推荐每个class都创建一个私有的静态实例。
class Program
private static Logger logger = LogManager.GetCurrentClassLogger();
static void Main(string[] args)
上面的代码将会以类名作为Logger实例的名字。等同于下面的方式:
Logger logger = LogManager.GetLogger(&Program&);
当然,logger是线程安全的。
Log levels
这里不是简单的枚举实现。
logger.Trace(&Sample trace message&);
logger.Debug(&Sample debug message&);
(&Sample informational message&);
logger.Warn(&Sample warning message&);
logger.Error(&Sample error message&);
logger.Fatal(&Sample fatal error message&);
logger., &Sample informational message&);
int k = 42;
int l = 100;
logger.Trace(&Sample trace message, k={0}, l={1}&, k, l);
logger.Debug(&Sample debug message, k={0}, l={1}&, k, l);
(&Sample informational message, k={0}, l={1}&, k, l);
logger.Warn(&Sample warning message, k={0}, l={1}&, k, l);
logger.Error(&Sample error message, k={0}, l={1}&, k, l);
logger.Fatal(&Sample fatal error message, k={0}, l={1}&, k, l);
logger., &Sample informational message, k={0}, l={1}&, k, l);
由于性能原因,这里推荐使用logger自带的参数化格式字符串,而不是自己手动去拼接(string.format或者concat)。具体原因是因为格式化字符串会有性能损失,nlog 内部会延迟格式化字符串。只有当真正需要输出字符串的时候才去做。某些配置可以忽略日志的情况下,可以省去格式字符串的性能损耗。
Configuration
最简单的配置:
&?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&&
&target name=&logfile& xsi:type=&File& fileName=&file.txt& /&
&/targets&
&logger name=&*& minlevel=&Info& writeTo=&logfile& /&
设置多个Targets
&nlog xmlns=&http://www.nlog-project.org/schemas/NLog.xsd&
xmlns:xsi=&http://www.w3.org/2001/XMLSchema-instance&&
&target name=&logfile& xsi:type=&File& fileName=&file.txt& /&
&target name=&console& xsi:type=&Console& /&
&/targets&
&logger name=&*& minlevel=&Trace& writeTo=&logfile& /&
&logger name=&*& minlevel=&Info& writeTo=&console& /&
指定logger name
&nlog xmlns=&http://www.nlog-project.org/schemas/NLog.xsd&
xmlns:xsi=&http://www.w3.org/2001/XMLSchema-instance&&
&target name=&logfile& xsi:type=&File& fileName=&file.txt& /&
&/targets&
&logger name=&ponent.*& minlevel=&Trace& writeTo=&logfile& final=&true& /&
&logger name=&*& minlevel=&Info& writeTo=&logfile& /&
&target name=&logfile& xsi:type=&File& fileName=&file.txt& layout=&${date:format=yyyyMMddHHmmss} ${message}& /&
Layout 分为简单的和格式化的。简单的Layout 如上所示就是定制输出的string 格式,结构化的Layout可以输出XML,CSV...
Wrappers 本身不做任何log的事情,只是修改logger 的行为。
&nlog xmlns=&http://www.nlog-project.org/schemas/NLog.xsd&
xmlns:xsi=&http://www.w3.org/2001/XMLSchema-instance&&
&target name=&asyncFile& xsi:type=&AsyncWrapper&&
&target name=&logfile& xsi:type=&File& fileName=&file.txt& /&
&/targets&
&logger name=&*& minlevel=&Info& writeTo=&asyncFile& /&
一般常用的是AsyncWrapper,FilteringWrapper,需要更多的Wrappers点
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:1380次
排名:千里之外
原创:12篇NLog日志使用方法 - 推酷
NLog日志使用方法
Nlog是一款可以通过自动化配置来把log信息指定写入 win console,Sql server,甚至是通过STMP 发送邮件的log engine
首先下载Nlog DLL,通过网上直接download 或者nuget 下载DLL都可以。
http://nlog-project.org/download/
然后把下载下来的Nlog.dll ,Nlog,extension.dll 加入项目reference.
我暂时只加载了Nlog,因为还没去研究Nlog.extension有什么功能。
之后就是配置文件了,(Nlog Configuration), 它其实是一个 config文件Name:(
Nlog.config
格式如下:
&?xml version=
&nlog xmlns=
xmlns:xsi=
for information on customizing logging rules and outputs.
&!-- add your targets here --&
&target xsi:type=
&${basedir}/logs/${shortdate}.log&
&${longdate} ${uppercase:${level}} ${message}&
&/targets&
&!-- add your logging rules here --&
&logger name=
或者如果你是WebAPP的话,可以把config直接写在web.config的&configuration&节点下,
我比较喜欢这种
&configuration&
& &configSections&
& & &section name=&
& type=&NLog.Config.ConfigSectionHandler, NLog&/&
& &/configSections&
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&
& & & &target xsi:type=&File& name=&f& fileName=&${basedir}/APP_Data/logs/${shortdate}.log& layout=&${longdate} ${uppercase:${level}} ${message}& /&&
& & &/targets&
& & &rules&
& & & &logger name=&*& minlevel=&Trace& writeTo=&f& /&
& & &/rules&
&/configuration&
接下来就是比较有技术含量的东西了,如何把log写入数据库,或者发邮件通知,也是通过配置文件,配置如下:
&!--nlog debug start--&
&!--&nlog xmlns=&&
xmlns:xsi=&&
throwExceptions=&true& internalLogFile=&c:\nlog.txt& internalLogLevel=&Debug& autoReload=&true&&--&
&!--nlog debug end--&
for information on customizing logging rules and outputs.
&!-- add your targets here --&
&!--&target xsi:type=&File& name=&f& fileName=&${basedir}/App_Data/logs/${shortdate}.log&
layout=&${longdate} ${uppercase:${level}} ${message}& /&--&
&${basedir}/App_Data/logs/${shortdate}.log&
&${longdate} ${uppercase:${level}} ${loginuser} ${message} ${machinename} ${exception:format=type} ${callsite:className=true} ${logger} ${exception:stacktrace} ${exception:format=tostring}&
&Database&
dbProvider
commandText
&Insert into NLog_Record(time_stamp, level, host, url, type, source, logger, message, stacktrace, detail, loginuser) Values(@time_stamp, @level, @host, @url, @type, @source, @logger, @message, @stacktrace, @detail, @loginuser);&
connectionString
&Data Source=Initial Catalog=Log_DB;Persist Security Info=TUser ID=資料庫登入帳號;Password=資料庫登入密碼;&
&!--&parameter name=&@time_stamp& layout=&${longdate}& /&--&
&@time_stamp&
&${date:format=yyyy\-MM\-dd HH\:mm\:ss.fff} &
&${level}&
&${machinename}&
&${aspnet-request:serverVariable=url}&
&${exception:format=type}&
&${callsite:className=true}&
&${logger}&
&@message&
&${message}&
&@stacktrace&
&${exception:stacktrace}&
&${exception:format=tostring}&
&@loginuser&
&${loginuser}&
&FatalMail&
smtpServer
smtpAuthentication
smtpUsername
&你要寄出的Email帳號&
smtpPassword
&寄出Email的密碼&
addNewLines
&寄出的Email&
&收信的Email,收信的Email2&
&${machinename} 於 ${shortdate} ${time} Log級別:${level} 於 ${callsite:className=true}, 出現 ${exception:format=type}!&
&=========================================================================&
body=&${newline}
發生時間:${longdate} ${newline}${newline}
Log等級:${
level:uppercase
} ${newline}${newline}
Logger:${logger} ${newline}${newline}
Source:${
callsite:className
} ${newline}${newline}
使用者:${loginuser} ${newline}${newline}
Exception類別:${
exception:format
} ${newline}${newline}
錯誤訊息:${message} ${newline}${newline}&
&=========================================================================&
bufferSize
&ErrorMail&
&BufferingWrapper&
smtpServer
smtpAuthentication
smtpUsername
&你要寄出的Email帳號&
smtpPassword
&寄出Email的密碼&
addNewLines
&寄出的Email&
&收信的Email,收信的Email2&
&${machinename} 於 ${shortdate} ${time} Log級別:${level} 出現錯誤!&
&=========================================================================&
body=&${newline}
發生時間:${longdate} ${newline}${newline}
Log等級:${
level:uppercase
} ${newline}${newline}
Logger:${logger} ${newline}${newline}
Source:${
callsite:className
} ${newline}${newline}
使用者:${loginuser} ${newline}${newline}
Exception類別:${
exception:format
} ${newline}${newline}
錯誤訊息:${message} ${newline}${newline}&
&=========================================================================&
&!-- add your logging rules here --&
&FatalMail&
&ErrorMail&
需要注意的是,配置文件的
&target& 存放log的地方,文件 & & & & &/数据库/邮件
&rule& & &是写入/显示log的方式
最后就是Nlog的语句了:
private static Logger logger = LogManager.GetCurrentClassLogger();
& & & & public ActionResult Index()
& & & & & & logger.Trace(&Sample trace message&);
& & & & & & logger.Debug(&Sample debug message&);
& & & & & & (&Sample informational message&);
& & & & & & logger.Warn(&Sample warning message&);
& & & & & & logger.Error(&Sample error message&);
& & & & & & logger.Fatal(&Sample fatal error message&);
& & & & & & // alternatively you can call the Log() method&
& & & & & & // and pass log level as the parameter.
& & & & & & logger., &Sample informational message&);
如果你写入的是consoleApp,你会发现不同的log颜色会不同,一目了然
已发表评论数()
请填写推刊名
描述不能大于100个字符!
权限设置: 公开
仅自己可见
正文不准确
标题不准确
排版有问题
主题不准确
没有分页内容
图片无法显示
视频无法显示
与原文不一致}

我要回帖

更多关于 卸载软件 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信