0

In my console app, I'm getting info: logs as shown below. Is there any way to turn-off this log?

Screenshot of console app1

canton7
  • 37,633
  • 3
  • 64
  • 77
s.k.paul
  • 7,099
  • 28
  • 93
  • 168

1 Answers1

0

Yes, this can be done in your EF configuration, see:

https://learn.microsoft.com/en-us/ef/core/logging-events-diagnostics/simple-logging#configuration-for-specific-messages

For ex:

    /// <summary>
    /// Configures our preferred default values for the db context
    /// </summary>
    /// <param name="optionsBuilder"></param>
    public static DbContextOptionsBuilder ConfigureDefaultsForDbContext(this DbContextOptionsBuilder optionsBuilder)
    {

#if DEBUG
        optionsBuilder.EnableDetailedErrors();
        optionsBuilder.EnableSensitiveDataLogging();
#endif

        // Stop log spamming
        optionsBuilder.ConfigureWarnings(builder => builder.Log(
            (RelationalEventId.CommandExecuting, LogLevel.Trace),
            (RelationalEventId.CommandExecuted, LogLevel.Debug),
            (CoreEventId.ContextInitialized, LogLevel.Trace)

#if DEBUG
            ,(CoreEventId.SensitiveDataLoggingEnabledWarning, LogLevel.None)
#endif
        ));

        return optionsBuilder;
    }

// In your dbContext:


protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    base.OnConfiguring(optionsBuilder);

    optionsBuilder.ConfigureOPGDefaultsForDbContext();

    // NOTE We have MARS enabled which will cause save points to not work.
    //      This is a feature where within a single transaction save points can be created, and rolled back to.
    //      Transaction in general WILL work - but EF generates a warning about this.
    //      We don't use save points - so we disable the warning. Assume any transactions will be rolled back completely.
    //      See: https://github.com/dotnet/efcore/issues/23269
    //      Also see: https://docs.microsoft.com/en-us/ef/core/saving/transactions#savepoints
    optionsBuilder.ConfigureWarnings(w => w.Ignore(SqlServerEventId.SavepointsDisabledBecauseOfMARS));
}

sommmen
  • 6,570
  • 2
  • 30
  • 51