假设我的 nlog.config 中有以下内容(取自http://nlog-project.org/documentation/v2.0.1/html/T_NLog_Targets_MemoryTarget.htm 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>
如何以编程方式访问该目标?我正在尝试在文本框中显示日志。
这里完全相同的问题,这对我有用:
var target =(MemoryTarget)LogManager.Configuration.FindTargetByName("memory");
var log = string.Join("\r\n", target.Logs);
txtLog.Text = log;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)