3

After installing NLog and NLog.config using NuGet package manager I am unable to edit NLog.config, it shows lock icon on it. How to unlock it?

lock icon on NLog.config file

my solution explorer

Julian
  • 33,915
  • 22
  • 119
  • 174
user8886083
  • 29
  • 1
  • 3
  • 6

3 Answers3

5

For newer projects the NLog.Config package is not recommended.

From: https://www.nuget.org/packages/NLog.config

Note: Unfortunately this package won't work well when using <PackageReference>

Advised to:

Julian
  • 33,915
  • 22
  • 119
  • 174
3

I had the same problem - the NuGet package for Nlog config was installed in a different location than the root project directory, like for example C:\Users\User\.nuget\packages\nlog.config\4.7.7\contentFiles\any\any\NLog.config instead of I:\workspaceVS\net50\ConsoleCoreApp1.

I managed to solved the problem by copying manually the file Nlog.config into the project's root directory and then reference it in my .csproj file in the following way :

<Project Sdk="Microsoft.NET.Sdk">
  ...
  <ItemGroup>    
    <None Update="NLog.config">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="NLog.xsd">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    ...
  <ItemGroup>
</Project>

instead of :

<Project Sdk="Microsoft.NET.Sdk">
  ...
  <ItemGroup>    
    <None Update="C:\Users\User\.nuget\packages\nlog.config\4.7.7\contentFiles\any\any\NLog.config">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="C:\Users\User\.nuget\packages\nlog.schema\4.7.7\contentFiles\any\any\NLog.xsd">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    ...
  <ItemGroup>
</Project>

And now, when I release it, it shows directly in the output directory :

.(I:\workspaceVS\net50\ConsoleCoreApp1\bin\Release\net5.0\win-x86)
├── ...                   
└── Nlog.config           # Holds the configuration for Nlog
Dharman
  • 30,962
  • 25
  • 85
  • 135
R13mus
  • 752
  • 11
  • 20
  • It worked great, only thing I also had to manually copy NLog.xsd also into the root of the project. Thanks for your solution. – JaisG May 06 '22 at 10:45
0

You can find the NLog.config file in {Project Folder}\bin\Debug\net5.0\. You can open and edit it as you like with Notepad or Visual Studio.

Chrᴉz remembers Monica
  • 1,829
  • 1
  • 10
  • 24
  • This comment does not answer the actual question. The NLog.config file is locked for editing. How to unlock? – Diana Mar 23 '22 at 17:46