trying to follow this tutorial : https://nblumhardt.com/2019/10/serilog-in-aspnetcore-3/
I managed to add the Serilog to my app (.NET Core 3.1)
but I cannot modify the CreateHostBuilder function, since it does not recognize UseSerilog() function
I have checked for a solution, but everyone seems to use that code
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Serilog;
namespace MyApi
{
public class Program
{
public static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.WriteTo.Console()
.CreateLogger();
try
{
Log.Information("Starting up");
CreateHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Application start-up failed");
}
finally
{
Log.CloseAndFlush();
}
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.UseSerilog() // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< unknown function
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
}
what am I missing here ?
thanks for your help
Configure Serilog in ASP.NET CoreBy specifying the configuration in the appsettings. json file we will be able to change the configuration or add/remove sinks without code changes. Now change the code in the program. cs to specify Host Builder to use Serilog in ASP.NET Core instead of default logger.
Serilog is a . NET library that provides diagnostic logging to files, the console, and almost everywhere you would like. Serilog can be used in classic . NET Framework applications and for applications running on the latest and greatest .
It's designed to work well with others. Serilog is the reference example of a Structured Logging system - one that doesn't just create messages, it easily captures key attributes and data about the context the message happened in.
Host Builder is a static class that provides two methods and when we call these methods, they will add some features into ASP.NET Core Applications. The Host Builder Provides two convenient methods for creating instances of IHostBuilder with pre-configured defaults.
'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.
Calling UseSerilog without any argument should be enough. You need to take on a dependency on Serilog.Extensions.Hosting to be able to call UseSerilog on the Host builder. Thanks for contributing an answer to Stack Overflow!
So Serilog is one of the most popular Libraries for ASP.NET Core Applications. What is Serilog? Console Logging. File Logging. Database Logging. What is Serilog?
If you're familiar with Serilog configuration in .NET 5, the first thing you'll try to do is call UseSerilog () on WebApplicationBuilder: using Serilog; var builder = WebApplication.CreateBuilder(args) .UseSerilog(...);
Answer provided by Alex Lyalka : packages were missing
dotnet add package Serilog.AspNetCore
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