Turn off Logging during Release from Nlog.config

9.1k Views Asked by At

Now i am doing like this

LogManager.DisableLogging();

But this need to deploy my code again, how can I disable loggin from nlog configuration file.

2

There are 2 best solutions below

0
On BEST ANSWER
 <nlog globalThreshold="Off" />
0
On

This may help - In the csproj file, you need to add Condition="'$(Configuration)' == 'Debug'" where you include NLog.config Example:

<Project>
    ...
    <ItemGroup>
        <Content Include="NLog.config" Condition="'$(Configuration)' == 'Debug'">
          <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </Content>  
    </ItemGroup>
    ...
</Project>

This way, in release mode it should not log anything because the NLog.config is not included.