Skip to content

Getting the following error using Serilog.Settings.Configuration #119

@jwebber974

Description

@jwebber974

Hello,

We are using the configuration library with a asp.net core 2.1 app and we are getting the following error when we try to build the logging configuration:

This is how we are building the configuration:

var configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();

        var assemblyInfo = Assembly.GetEntryAssembly().GetName();
        Log.Logger = new LoggerConfiguration()
            .ReadFrom.Configuration(configuration)
            .MinimumLevel.Verbose()
            .Enrich.WithProcessId()
            .Enrich.WithEnvironmentUserName()
            .Enrich.WithMachineName()
            .Enrich.WithThreadId()
            .Enrich.WithProperty("ApplicationName", assemblyInfo.Name)
            .Enrich.WithProperty("Version", assemblyInfo.Version.ToString())
            .Enrich.FromLogContext()
            .CreateLogger();

This is the error:

Application: Integration.WebApi.exe
CoreCLR Version: 4.6.26606.2
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeLoadException: Could not load type 'System.Web.IHttpModule' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at System.Reflection.RuntimeAssembly.GetExportedTypes(RuntimeAssembly assembly, ObjectHandleOnStack retTypes)
at System.Reflection.RuntimeAssembly.GetExportedTypes()
at Serilog.Settings.Configuration.ConfigurationReader.<>c.b__23_0(Assembly a)
at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext() at System.Linq.Enumerable.SelectManySingleSelectorIterator2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator1.ToList() at System.Linq.Enumerable.ToList[TSource](IEnumerable1 source)
at Serilog.Settings.Configuration.ConfigurationReader.FindEventEnricherConfigurationMethods(IReadOnlyCollection1 configurationAssemblies) at Serilog.Settings.Configuration.ConfigurationReader.ApplyEnrichment(LoggerConfiguration loggerConfiguration, IReadOnlyDictionary2 declaredLevelSwitches)
at Serilog.Settings.Configuration.ConfigurationReader.Configure(LoggerConfiguration loggerConfiguration)
at Serilog.Configuration.LoggerSettingsConfiguration.Settings(ILoggerSettings settings)
at Integration.WebApi.Program.Main(String[] args) in C:\src\igsolutions_repo\Code\Integration.WebApi\Program.cs:line 21

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions