在NLog中访问内存目标 [英] Access Memory Target in NLog
本文介绍了在NLog中访问内存目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我的nlog.config中包含以下内容(取自 http://nlog-project.org/documentation/v2.0.1/html/T_NLog_Targets_MemoryTarget.htm ):
Lets say I have the following in my nlog.config (taken from http://nlog-project.org/documentation/v2.0.1/html/T_NLog_Targets_MemoryTarget.htm):
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets>
<target name="memory" xsi:type="Memory" layout="${message}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="memory" />
</rules>
</nlog>
如何通过编程方式访问此目标?我正在尝试在文本框中显示日志.
How do I access this target programatically? I am trying to display the logs in a text box.
推荐答案
这里的问题完全相同,这对我有用:
Exactly the same issue here, this worked for me:
var target =(MemoryTarget)LogManager.Configuration.FindTargetByName("memory");
var log = string.Join("\r\n", target.Logs);
txtLog.Text = log;
这篇关于在NLog中访问内存目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文