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:
Install package Serilog.Extensions.Logging.File
with 1.1.0
<PackageReference Include="Serilog.Extensions.Logging.File" Version="1.1.0" />
Register AddFile
in Startup.cs
public void Configure(IApplicationBuilder app, IHostingEnvironment env,
ILoggerFactory loggerFactory)
{
loggerFactory.AddFile("Logs/app-{Date}.txt");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With