"UseSerilog()" Latest version with .net core 2.2
See original GitHub issueUnfortunately, I can’t upgrade my project to 3.0 yet, which is why I’m still on 2.2. I’ve just installed the latest version of serilog and now “UseSerilog” is invalid. I know that 3.0 changed some of the setup in Program.cs, e.g. changing IWebHostBuilder to IHostBuilder, so I’m wondering whether the latest version is only built for 3.0?
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Serilog;
using Serilog.Events;
using System;
namespace myapp
{
public class Program
{
public static int Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.File("log.txt", rollingInterval: RollingInterval.Day)
.CreateLogger();
try
{
Log.Information("Starting web host");
CreateWebHostBuilder(args).Build().Run();
return 0;
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
return 1;
}
finally
{
Log.CloseAndFlush();
}
}
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseSetting("https_port", "443")
.UseStartup<Startup>()
.UseSerilog(); // this line has an error
}
}
‘IWebHostBuilder’ does not contain a definition for ‘UseSerilog’ and no accessible extension method ‘UseSerilog’ accepting a first argument of type ‘IWebHostBuilder’ could be found (are you missing a using directive or an assembly reference?)
What am I missing? When googling old serilog tutorials they all use “UseSerilog()” for IWebHostBuilder.
Oh and the following packages are installed:
- Serilog
- Serilog.Sinks.Async
- Serilog.Sinks.Console
- Serilog.Sinks.File
Thanks for some help!
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top Results From Across the Web
ASP.NET Core 2.2 - Serilog | Missing out on events
In my case I have to set Serilog's ILogger from Core library in Startup.cs/Configure() method. Program.cs public static IWebHostBuilder ...
Read more >Configuring Serilog in ASP.NET Core 2.2 web API
NET Core version 2.2 's web api. Click here to learn how to create a new web API. Why use Serilog? Serilog provides...
Read more >Setting Up Serilog in a .NET Core 2.2 Web App Deployed ...
Step 1: Install the Following Nuget Packages · Step 2: Make Changes to the appsettings.Development. · Step 3: Create a New or Make...
Read more >Setting up Serilog in ASP.NET Core - Detailed Beginner ...
This article covers the implementation of Serilog in ASP.NET Core which provides structured logging that is easier to be read by programs.
Read more >Serilog — simple .NET logging with fully-structured events
NET, Serilog provides diagnostic logging to files, the console, and elsewhere. It is easy to set up, has a clean API, and is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Istead of installing serilog.aspnetcore, you could just do
I do this when running console applications, where i don’t need aspnetcore.
Interesting - the
UseSerilog()
extension forIWebHostBuilder
/.NET Core 2.2 is still supported, could there have been a package installation/upgrade issue? I notice that Serilog.AspNetCore isn’t in the list of packages in your post - just an oversight?