简体   繁体   中英

Attempting to reading Serilog config from appsettings.json

I'm converting ac# project to .Net Core (not ASP.Net core) and cannot get the examples posted on the Serilog site to compile. I must be missing something simple. I'm trying to read the Serilog config from appsettings.json. Below is the code from the site:

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

    var logger = new LoggerConfiguration()
        .ReadFrom.Configuration(configuration)
        .CreateLogger();

The problem I'm having is that .Build() returns a Microsoft.Framework.Configuration.IConfigurationRoot . ReadFrom.Configuration() is expecting a Microsoft.Extensions.Configuration.IConfiguration object. I tried using Microsoft.Extensions.Configuration.ConfigurationBuilder() but there is no .AddJsonFile() . Has anyone else used this code and can point me in the right direction? Thanks in advance for any assistance.

It looks like you may have installed an old version of Serilog.Settings.Configuration or some other package - any reference you see to Microsoft.Framework.* is an old pre-1.0 package that won't work with the current .NET Core bits.

In particular, make sure no packages are referencing Microsoft.Framework.Configuration , and upgrade any that do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM