Nlog: Could not find file Nlog.config in .Net core 3.1 on ubuntu

Created on 9 Jul 2020  路  3Comments  路  Source: NLog/NLog

Hi,
I use NLog and it's work on windows but when I publish it on ubuntu, on start I get this error:

Unhandled exception. System.IO.FileNotFoundException: Could not find file '/home/masium/var/www/api/NLog.config'. File name: '/home/masium/var/www/api/NLog.config' at Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, String path, Boolean isDirectory, Func2 errorRewriter)
at Microsoft.Win32.SafeHandles.SafeFileHandle.Open(String path, OpenFlags flags, Int32 mode)
at System.IO.FileStream.OpenHandle(FileMode mode, FileShare share, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials, IWebProxy proxy, RequestCachePolicy cachePolicy)
at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
at System.Xml.XmlTextReaderImpl.FinishInitUriString()
at System.Xml.XmlTextReaderImpl..ctor(String uriStr, XmlReaderSettings settings, XmlParserContext context, XmlResolver uriResolver)
at System.Xml.XmlReaderSettings.CreateReader(String inputUri, XmlParserContext inputContext)
at System.Xml.XmlReader.Create(String inputUri)
at NLog.Internal.Fakeables.AppEnvironmentWrapper.LoadXmlFile(String path)
at NLog.Config.LoggingConfigurationFileLoader.LoadXmlLoggingConfigurationFile(LogFactory logFactory, String configFile)
at NLog.Config.LoggingConfigurationFileLoader.Load(LogFactory logFactory, String filename)
at NLog.LogFactory.LoadConfiguration(String configFile)
at NLog.LogManager.LoadConfiguration(String configFile)
at NLog.Web.NLogBuilder.ConfigureNLog(String configFileName)
at IFS.Core.Logger.LoggerConfiguration.Config() in C:\Users\MasBa\sourcerepos\IFS\BaseSolution\IFS.Core\Logger\LoggerConfiguration.cs:line 10
at IFS.Red.WebApi.Startup.<>c__DisplayClass7_0.b__1() in C:\Users\MasBa\sourcerepos\IFSRedSolution\IFS.Red.WebApi\Startup.cs:line 90
at IFS.Core.MBCore.BuildUp(IServiceCollection serviceCollection, IConfiguration configuration, Action config, Action1 iocConfig, Action1 iocScanner, Action1 iocSetter, List1 assemblyNames) in C:\Users\MasBa\sourcerepos\IFS\BaseSolution\IFS.Core\MBCore.cs:line 35
at IFS.Red.WebApi.Startup.ConfigureServices(IServiceCollection services) in C:\Users\MasBa\sourcerepos\IFSRedSolution\IFS.Red.WebApi\Startup.cs:line 113
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.g__Startup|0(IServiceCollection serviceCollection)
at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder1.<>c__DisplayClass15_0.<BuildStartupServicesFilterPipeline>g__RunPipeline|0(IServiceCollection services) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.<Build>b__0(IServiceCollection services) at Microsoft.AspNetCore.Hosting.StartupLoader.ConfigureServicesDelegateBuilder1.<>c__DisplayClass14_0.g__ConfigureServicesWithContainerConfiguration|0(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
at Microsoft.AspNetCore.Hosting.WebHost.EnsureApplicationServices()
at Microsoft.AspNetCore.Hosting.WebHost.Initialize()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
at IFS.Red.WebApi.Program.Main(String[] args) in C:\Users\MasBa\sourcerepos\IFSRedSolution\IFS.Red.WebApi\Program.cs:line 10
Aborted (core dumped)`

but the NLog.cofig file is exist on '/home/masium/var/www/api/NLog.config'.
Can everybody help me?

nlog-configuration question

Most helpful comment

Maybe you have an issue with filename case. When deployed is the file NLog.config or nlog.config ?

What input string do you provide in LoggerConfiguration.cs:line 10 when calling NLogBuilder.ConfigureNLog(...); ?

All 3 comments

Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better!

Maybe you have an issue with filename case. When deployed is the file NLog.config or nlog.config ?

What input string do you provide in LoggerConfiguration.cs:line 10 when calling NLogBuilder.ConfigureNLog(...); ?

The file name was Nlog.config but I set it in code NLog.config
thanks for help.

Was this page helpful?
0 / 5 - 0 ratings