适用于SQLite的.NET Core 3.0 ConsoleLoggerFactory

编程入门 行业动态 更新时间:2024-10-26 04:24:30
本文介绍了适用于SQLite的.NET Core 3.0 ConsoleLoggerFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

使用最新的.Net Core(3.0预览版)和EF Core(3.0预览版)查看一些在线资源,我这样做:

using latest .Net Core (3.0 preview) and EF Core (3.0 preview) looking at a few online sources I did this:

Program.cs

public class MainWorker : IHostedService { public static readonly ILoggerFactory ConsoleLoggerFactory = LoggerFactory.Create(builder => builder.AddConsole();

MyDbContext.cs

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { string connectionString = ... optionsBuilder .UseLoggerFactory(MainWorker.ConsoleLoggerFactory) .EnableSensitiveDataLogging(true) .UseSqlite(connectionString); }

所有这些都构建并运行良好,但是当使用EF查询数据库而不是仅 的实际SQL查询时,看到的条目如下:

This all builds and runs fine but when using EF to query my DB instead of the actual SQL queries I only see are entries such as:

信息:Microsoft.EntityFrameworkCore.Infrastructure [10403]实体框架核心3.0.0-preview4.19176.6使用提供程序初始化了"MyDbContext"带有选项的"Microsoft.EntityFrameworkCore.Sqlite":SensitiveDataLoggingEnabled

info: Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 3.0.0-preview4.19176.6 initialized 'MyDbContext' using provider 'Microsoft.EntityFrameworkCore.Sqlite' with options: SensitiveDataLoggingEnabled

如何获取IQueryable的实际SQL查询?

How can I get the actual SQL query for an IQueryable ?

有帮助吗?

推荐答案

更新:根据提供的反馈,以下更改为已恢复在3.0预览版7中.

Update: Based on the provided feedback, the below change has been reverted in 3.0 preview 7.

这是预期的重大更改-查询执行记录在调试级.

该链接说明了为什么原因以及如何使用 DbContextOptionsBuilder 恢复在 Info 级别(默认)记录SQL的先前行为:

The link explains why is that and how to get back the previous behavior of logging SQL at Info level (the default) using the DbContextOptionsBuilder:

.ConfigureWarnings(c => c.Log((RelationalEventId.CommandExecuting, LogLevel.Info)));

另一种方法是使用 AddFilter 方法将 DbLoggerCategory.Database.Command 类别的最低日志级别更改为 Debug > ILoggingBuilder :

Another way is to change the minimum log level for DbLoggerCategory.Database.Command category to Debug using the AddFilter method of the ILoggingBuilder:

.AddFilter(DbLoggerCategory.Database.Command.Name, LogLevel.Debug)

更多推荐

适用于SQLite的.NET Core 3.0 ConsoleLoggerFactory

本文发布于:2023-11-15 03:01:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1590563.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:适用于   SQLite   NET   ConsoleLoggerFactory   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!