I'm having some issues with NLog, .NET Core 2.2 AspNet Api project and debugging a Docker container in Visual Studio 2017.
I've followed the setup guide on the NLog Github site, added the code to the Program Main method, created an nlog.config file:
var logger = NLog.Web.NLogBuilder.ConfigureNLog("nlog.config").GetCurrentClassLogger();
Debug.Write(logger);
try
{
logger.Debug("init main");
CreateWebHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
//NLog: catch setup errors
logger.Error(ex, "Stopped program because of exception");
throw;
}
finally
{
// Ensure to flush and stop internal timers/threads before application-exit (Avoid segmentation fault on Linux)
NLog.LogManager.Shutdown();
}
The application runs incredibly slow, it takes an age to configure the logger. But it does eventually get the config file.
If I follow the Output whilst it's doing this, I get a continuous list of error messages as follows:
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Private.CoreLib.dll'. Cannot find or open the PDB file.
Loaded '/app/bin/Debug/netcoreapp2.2/SharpGaming.Api.Gateway.Ui.dll'. Symbols loaded.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Runtime.dll'. Module was built without symbols.
Loaded '/root/.nuget/fallbackpackages2/nlog/4.6.5/lib/netstandard2.0/NLog.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/netstandard.dll'. Module was built without symbols.
Loaded '/root/.nuget/fallbackpackages2/nlog.web.aspnetcore/4.8.3/lib/netstandard2.0/NLog.Web.AspNetCore.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Diagnostics.Debug.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.AspNetCore.App/2.2.5/Microsoft.AspNetCore.Hosting.Abstractions.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.AspNetCore.App/2.2.5/Microsoft.AspNetCore.Hosting.dll'. Cannot find or open the PDB file.
Step into: Stepping over property 'NLog.Config.ConfigurationItemFactory.get_Default'. To step into properties or operators, go to Tools->Options->Debugging and uncheck 'Step over properties and operators (Managed only)'.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Runtime.Extensions.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Collections.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.ComponentModel.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Diagnostics.TraceSource.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Net.Primitives.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Data.Common.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Net.Mail.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Threading.ThreadPool.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.IO.FileSystem.Watcher.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Net.Sockets.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.ComponentModel.TypeConverter.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Threading.Tasks.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Linq.Expressions.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Linq.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Diagnostics.Tools.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Private.Uri.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.IO.FileSystem.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Memory.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Buffers.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Threading.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Runtime.InteropServices.dll'. Module was built without symbols.
Loaded '/root/.nuget/fallbackpackages2/nlog.extensions.logging/1.5.1/lib/netstandard2.0/NLog.Extensions.Logging.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Xml.ReaderWriter.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Private.Xml.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Threading.Thread.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Security.Cryptography.Algorithms.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Text.Encoding.Extensions.dll'. Module was built without symbols.
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Collections.Specialized.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Drawing.Primitives.dll'. Cannot find or open the PDB file.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Threading.Timer.dll'. Module was built without symbols.
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.ComponentModel.Primitives.dll'. Cannot find or open the PDB file.
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Collections.Concurrent.dll'. Cannot find or open the PDB file.
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Loaded '/usr/share/dotnet/shared/Microsoft.AspNetCore.App/2.2.5/Microsoft.AspNetCore.Http.Abstractions.dll'. Cannot find or open the PDB file.
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
This goes on for several more Exceptions
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Console.dll'. Cannot find or open the PDB file.
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Loaded '/usr/share/dotnet/shared/Microsoft.NETCore.App/2.2.5/System.Diagnostics.StackTrace.dll'. Module was built without symbols.
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
Exception thrown: 'System.IO.IOException' in System.Private.CoreLib.dll
... and several more. That's just it configuring the logger.
It continues to do this once the logger has loaded.
I figured that perhaps it was running in Debug, but the DockerFile had created a Release package. So I tried changing this so it ran as either Release or Debug, still does the same thing.
The deployed code to the docker instance doesn't include the PDB files, which I would expect.
It's almost like the NLog dll is trying to run in Debug, when it should be running in Release?
If I remove the setup code for NLog, everything works fine. I get no errors and the app runs smoothly and quickly in a docker container.
I'm using Windows for Docker and creating Linux Dockers.
Can anyone please help?