简体   繁体   English

配置 Serilog.Extensions.Logging.File

[英]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.按照Nicholas Blumhardt 页面和后来的Serilog github 页面上的说明,我在让 Serilog 工作时遇到了问题。 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?)错误 CS1061“ILoggerFactory”不包含“AddFile”的定义,并且找不到接受“ILoggerFactory”类型的第一个参数的扩展方法“AddFile”(您是否缺少 using 指令或程序集引用?)

I have downloaded the latest package from from NuGet.我已经从 NuGet 下载了最新的包。 My .proj has the following entry <PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />我的 .proj 有以下条目<PackageReference Include="Serilog.Extensions.Logging" Version="2.0.2" />

I've restarted Visual Studio after installing.安装后我重新启动了 Visual Studio。

Startup.cs (1st Tute) Startup.cs (第一次)

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

Program.cs (2nd Tute) Program.cs (第 2 节)

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使用1.1.0安装包Serilog.Extensions.Logging.File

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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