I'm migration from EF to EF Core 5.0 (preview 6 now), but there is no Log in DbContext.Database anymore.
using (MyDBContext db = ContextFactory.GetMyContext())
{
db.Database.Log = logInfo => FileLogger.Log(logInfo);
}
There is a new API for logging now: https://erikej.github.io/efcore/2020/05/18/ef-core-simple-logging.html
The API linked to above has been introduced for 5.0, which hasn't yet been released. Until that happens, you can still configure logging in EF Core as detailed in this page.
Ok, but this change logger for all entire DBContext.
In project which I am upgrading to EF Core there is only one call to DbContext.Database.Log - in only one controller endpoint.
How to achieve this in EF Core 5.0 preview 6?
@Saibamen You could setup a switch on the context to allow logging to be switched on when needed. For example:
```C#
public class SomeDbContext : DbContext
{
public bool LoggingEnabled { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.LogTo(s =>
{
if (LoggingEnabled)
{
Console.WriteLine(s);
}
})
.EnableSensitiveDataLogging()
.UseSqlServer(Your.SqlServerConnectionString);
}
```
Could be a useful addition to the docs.
Thanks
Most helpful comment
Could be a useful addition to the docs.