是否可以在不重新启动.NET应用程序的情况下激活Serilog或NLog中的日志记录?
我想在客户系统上运行该应用程序时激活日志记录,以了解问题所在。
NLog的主要功能之一是您可以在运行应用程序时更改配置。
如果有nlog.config,则可以启用自动重载:
<nlog autoReload="true">
...
</nlog>
然后将更改保存到文件时,将重新加载配置。
例如:
在配置中,您可以在运行时更改globalThreshold
或<rules>
。
<?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"
autoReload="true"
globalThreshold="Debug" >
<!-- the targets to write to -->
<targets>
<!-- write logs to file -->
<target xsi:type="File" name="file1" fileName="c:\temp\nlog-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
</targets>
<!-- rules to map from logger name to target -->
<rules>
<logger name="*" minlevel="Trace" writeTo="file1" />
</rules>
</nlog>