试图从appsettings.json读取Serilog配置

时间:2016-12-01 16:01:48

标签: c# json serilog

我正在将一个c#项目转换为.Net Core(而不是ASP.Net核心),并且无法获得在Serilog站点上发布的示例进行编译。我一定很遗憾。我正在尝试从appsettings.json读取Serilog配置。以下是该网站的代码:

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

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

我遇到的问题是.Build()返回一个 Microsoft.Framework.Configuration.IConfigurationRootReadFrom.Configuration()期待Microsoft.Extensions.Configuration.IConfiguration个对象。 我尝试使用Microsoft.Extensions.Configuration.ConfigurationBuilder(),但没有.AddJsonFile()。有没有其他人使用过此代码,可以指出我正确的方向?提前感谢您的任何帮助。

1 个答案:

答案 0 :(得分:0)

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.