You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NLog.NLogConfigurationException
HResult=0x80131500
Message=Failed to create LayoutRenderer with unknown type-alias: 'logDir' - Verify type-alias and check extension is included.
Source=NLog
StackTrace:
at NLog.Config.FactoryExtensions.CreateInstance[TBaseType](IFactory`1 factory, String typeAlias)
at NLog.Layouts.LayoutParser.GetLayoutRenderer(String typeName, ConfigurationItemFactory configurationItemFactory, Nullable`1 throwConfigExceptions)
at NLog.Layouts.LayoutParser.ParseLayoutRenderer(ConfigurationItemFactory configurationItemFactory, SimpleStringReader stringReader, Nullable`1 throwConfigExceptions)
at NLog.Layouts.LayoutParser.CompileLayout(ConfigurationItemFactory configurationItemFactory, SimpleStringReader sr, Nullable`1 throwConfigExceptions, Boolean isNested, String& text)
at NLog.Layouts.LayoutParser.CompileLayout(String value, ConfigurationItemFactory configurationItemFactory, Nullable`1 throwConfigExceptions, String& text)
at NLog.Layouts.SimpleLayout.SetLayoutText(String value, Nullable`1 throwConfigExceptions)
at NLog.Layouts.SimpleLayout..ctor(String txt, ConfigurationItemFactory configurationItemFactory, Nullable`1 throwConfigExceptions)
at NLog.Config.LoggingConfigurationParser.CreateSimpleLayout(String layoutText)
at NLog.Config.LoggingConfigurationParser.ParseVariableElement(ValidatedConfigurationElement variableElement)
at NLog.Config.LoggingConfigurationParser.ParseNLogSection(ILoggingConfigurationElement configSection)
at NLog.Config.LoggingConfigurationParser.LoadConfig(ILoggingConfigurationElement nlogConfig, String basePath)
at NLog.Extensions.Logging.NLogLoggingConfiguration.LoadConfigurationSection(IConfigurationSection nlogConfig)
at NLog.Extensions.Logging.NLogLoggingConfiguration..ctor(IConfigurationSection nlogConfig, LogFactory logFactory)
at NLog.Extensions.Logging.RegisterNLogLoggingProvider.<>c__DisplayClass1_0.<TryLoadConfigurationFromSection>b__0(ISetupLoadConfigurationBuilder configBuilder)
at NLog.SetupBuilderExtensions.LoadConfiguration(ISetupBuilder setupBuilder, Action`1 configBuilder)
at NLog.Extensions.Logging.RegisterNLogLoggingProvider.TryLoadConfigurationFromSection(NLogLoggerProvider loggerProvider, IConfiguration configuration)
at NLog.Extensions.Logging.RegisterNLogLoggingProvider.CreateNLogLoggerProvider(IServiceProvider serviceProvider, IConfiguration hostConfiguration, NLogProviderOptions options, LogFactory logFactory)
at NLog.Extensions.Logging.ConfigureExtensions.CreateNLogLoggerProvider(IServiceProvider serviceProvider, IConfiguration hostConfiguration, NLogProviderOptions options, LogFactory logFactory)
at NLog.Extensions.Logging.ConfigureExtensions.CreateNLogLoggerProvider(IServiceProvider serviceProvider, IConfiguration hostConfiguration, NLogProviderOptions options)
at NLog.Extensions.Logging.RegisterNLogLoggingProvider.<>c__DisplayClass0_1.<TryAddNLogLoggingProvider>b__2(IServiceProvider provider, IConfiguration cfg, NLogProviderOptions opt)
at NLog.Extensions.Logging.RegisterNLogLoggingProvider.<>c__DisplayClass0_0.<TryAddNLogLoggingProvider>b__4(IServiceProvider serviceProvider)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor(ConstructorCallSite constructorCallSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.Extensions.Hosting.HostBuilder.<>c__DisplayClass35_0.<PopulateServiceCollection>b__2(IServiceProvider _)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSiteMain(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache(ServiceCallSite callSite, RuntimeResolverContext context)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2.VisitCallSite(ServiceCallSite callSite, TArgument argument)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve(ServiceCallSite callSite, ServiceProviderEngineScope scope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.CreateServiceAccessor(ServiceIdentifier serviceIdentifier)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(ServiceIdentifier serviceIdentifier, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider)
at Microsoft.Extensions.Hosting.HostBuilder.ResolveHost(IServiceProvider serviceProvider, DiagnosticListener diagnosticListener)
at Microsoft.Extensions.Hosting.HostApplicationBuilder.Build()
at Microsoft.AspNetCore.Builder.WebApplicationBuilder.Build()
at Program.<Main>$(String[] args)
While writing this up, with some tinkering I was able to identify what I think is the cause of the issue and, in understanding that, I'm not certain if it will be considered a bug or a feature request or maybe just some additional documentation if it's decided that a fix is more work than its worth.
It appears that the main difference here is that NLog.config processes variables in the order they are defined, whereas the appsettings variety seems like it may be processing them in alphabetical order (probably a result of the underlying implementation details of the IConfiguration system). After fixing logDir by renaming it to z-logDir, MicrosoftLayout threw the same exception due to it referencing MicrosoftLevel (these names come straight from the documentation here).
Ideally it would be nice if the variables could still reference each other without needing to consider alphabetical ordering of their names, whether it did some sort of dependency sorting internally while parsing, or if there was a way to help it identify them with some additional json properties or some such.
Yes was also surprised that keys was sorted automatically when I did the initial implementation of loading NLog configuration from appsettings.json-file. The order shown in the config-file is not the order of how they would be parsed.
Since variables has the ability to reference other variables, then I guess one could make some funky logic that tries to produce custom sorting order when recognizing references. But the funky logic should be local in this repository.
Type: Bug(?)
NLog version: 5.2.8
NLog.Extensions.Logging version: 5.3.8
NLog.Web.AspNetCore version: N/A
Platform: .NET Standard 2.0, .NET Framework 4.8, .NET 8
Current NLog config
Converting from XML:
Found while converting to
Expected Result:
Variables can reference each other
Actual Result:
While writing this up, with some tinkering I was able to identify what I think is the cause of the issue and, in understanding that, I'm not certain if it will be considered a bug or a feature request or maybe just some additional documentation if it's decided that a fix is more work than its worth.
It appears that the main difference here is that NLog.config processes variables in the order they are defined, whereas the appsettings variety seems like it may be processing them in alphabetical order (probably a result of the underlying implementation details of the IConfiguration system). After fixing
logDir
by renaming it toz-logDir
,MicrosoftLayout
threw the same exception due to it referencingMicrosoftLevel
(these names come straight from the documentation here).Ideally it would be nice if the variables could still reference each other without needing to consider alphabetical ordering of their names, whether it did some sort of dependency sorting internally while parsing, or if there was a way to help it identify them with some additional json properties or some such.
Workaround:
The text was updated successfully, but these errors were encountered: