我在 DbContext 中有一个自定义方法,我想从中写入一些额外的日志:
public class MyDbContext : DbContext
{
public async Task CustomBulkInsert(...)
{
//how to write logs from here?
}
}
我不想注入我自己的 ILogger,因为 DbContext 已经构建了日志记录。
我在 DbContext 中有一个自定义方法,我想从中写入一些额外的日志:
public class MyDbContext : DbContext
{
public async Task CustomBulkInsert(...)
{
//how to write logs from here?
}
}
我不想注入我自己的 ILogger,因为 DbContext 已经构建了日志记录。
AddDbContext
如果您通过标准方法(如/)添加上下文AddDbContextFactory
,那么您只需将记录器注入构造函数即可:或者,如果您确实想要,您可以使用内部EF Core API(我不建议这样做,但仍然):
您可以访问 DbContext 内部使用的相同 ILogger。