Configuring Serilog RRS feed

  • Question

  • User-1204637165 posted

    So i have a troubling issue. Which is quite simple but I just not getting it.

     I am trying to configure serilog in such a way that it would not log normal sql statements and it would also log with date and time.

    I have my configuration done like this.

    public class Startup{
    public void Configure(IApplicationBuilder app,ILoggerFactory loggerFactory){
       //Facilitate logging here
       ILogger logger= loggerFactory.CreateLogger<Startup>();

    Please how do I make this stop logging sql queries. and log with time and date.

    Monday, July 13, 2020 3:18 PM

All replies

  • User711641945 posted

    Hi InspiredJide,

    You could use `MinimumLevel.Override`:

    public class Program
        public static void Main(string[] args)
            Log.Logger = new LoggerConfiguration()
    .MinimumLevel.Override("Microsoft.EntityFrameworkCore.Database.Command", LogEventLevel.Warning)
    .WriteTo.File("log.txt", rollingInterval: RollingInterval.Day)
    .CreateLogger(); CreateWebHostBuilder(args).Build().Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseSerilog() .UseStartup<Startup>(); }

    Best Regards,


    Tuesday, July 14, 2020 6:43 AM
  • User-1204637165 posted

    Thanks alot,.

    I actually have this in my Program.cs but the big challenge I have is that this method call

    That method is highlighted in red line. I don't know why, been battling with it for days.
    throws an error in my Program.cs file please look at my import in Program.cs class below

    using Serilog;
    using Serilog.Events;
    using Seriilog.Configuration;

    Please can you help me with hint on what can cause this.

    Wednesday, July 15, 2020 7:59 AM
  • User711641945 posted

    Hi InspiredJide,

    You need install `Serilog.AspNetCore` package:


    Best Regards,


    Thursday, July 16, 2020 8:44 AM
  • User-1204637165 posted

    Thanks Boss. I would do this and get back to you.

    Friday, July 17, 2020 11:07 AM