简体   繁体   中英

Configuring Serilog.Extensions.Logging.File

Following the instructions at Nicholas Blumhardt's page and later the Serilog github page , I am having issues getting Serilog to work. Specfically

Error CS1061 'ILoggerFactory' does not contain a definition for 'AddFile' and no extension method 'AddFile' accepting a first argument of type 'ILoggerFactory' could be found (are you missing a using directive or an assembly reference?)

I have downloaded the latest package from from NuGet. My .proj has the following entry <PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />

I've restarted Visual Studio after installing.

Startup.cs (1st Tute)

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    loggerFactory.AddFile("Logs/app-{Date}.txt");

Program.cs (2nd Tute)

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .ConfigureLogging((hostingContext, builder) =>
        {
            builder.AddFile("Logs/myapp-{Date}.txt");
        })
        .UseStartup<Startup>();

What makes this worse is I did this for a project over a year ago and comparing to that I can't see what I'm doing wrong :(

For one way, follow steps below:

  1. Install package Serilog.Extensions.Logging.File with 1.1.0

     <PackageReference Include="Serilog.Extensions.Logging.File" Version="1.1.0" />
  2. Register AddFile in Startup.cs

     public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { loggerFactory.AddFile("Logs/app-{Date}.txt");

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