从 Nlog.config 发布期间关闭日志记录
Turn off Logging during Release from Nlog.config
现在我是这样做的
LogManager.DisableLogging();
但是这需要再次部署我的代码,我怎样才能从 nlog 配置文件中禁用登录。
<nlog globalThreshold="Off" />
这可能会有所帮助 - 在 csproj 文件中,您需要在包含 NLog.config
的位置添加 Condition="'$(Configuration)' == 'Debug'"
示例:
<Project>
...
<ItemGroup>
<Content Include="NLog.config" Condition="'$(Configuration)' == 'Debug'">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
...
</Project>
这样,在发布模式下,它不会记录任何内容,因为 NLog.config 不包括在内。
现在我是这样做的
LogManager.DisableLogging();
但是这需要再次部署我的代码,我怎样才能从 nlog 配置文件中禁用登录。
<nlog globalThreshold="Off" />
这可能会有所帮助 - 在 csproj 文件中,您需要在包含 NLog.config
的位置添加 Condition="'$(Configuration)' == 'Debug'"
示例:
<Project>
...
<ItemGroup>
<Content Include="NLog.config" Condition="'$(Configuration)' == 'Debug'">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
</ItemGroup>
...
</Project>
这样,在发布模式下,它不会记录任何内容,因为 NLog.config 不包括在内。