8

I'm wondering how to add console logging to EF.Core without getting an "obsolete" warning.

Given: DbContextOptionsBuilder<BenchmarkDbContext> builder = ...;

I tried:

builder.UseLoggerFactory(new LoggerFactory().AddConsole())

And tried:

var factory = new LoggerFactory();

factory.AddProvider(new ConsoleLoggerProvider((a, b) => true, true));

builder.UseLoggerFactory(factory)
1
  • I don't like lambda expressions because I don't know how to debug them. What does '(a, b) => true, true)' actually do? Commented Jul 23, 2021 at 13:55

1 Answer 1

22

I think the initialization of logger is changed in EFCore 3.x. Try using this:

public static readonly ILoggerFactory factory 
    = LoggerFactory.Create(builder => { builder.AddConsole(); });

See details here.

1
  • Spot on. Thank you.
    – riemannzz
    Commented Apr 14, 2020 at 13:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.