Description
Hi @rowanmiller,
Currently EF logs raw strings without leveraging ASP.NET logging extensions.
source code
Filtering based on that string is very difficult if not impossible.
I wanted to create a pull request with a fix, I tried to compile the repository for hours but there were mismatch of assemblies I couldn't resolve for some reason.
Anyway the fix seems to be as simple as changing the code to:
logger.LogInformation((int) RelationalEventId.ExecutedCommand,
RelationalStrings.RelationalLoggerExecutedCommand,
string.Format(CultureInfo.InvariantCulture, "{0:N0}", elapsedMilliseconds),
command.Parameters
.Cast<DbParameter>()
.Select(
p => new DbParameterLogData(
p.ParameterName,
logParameterValues ? p.Value : "?",
logParameterValues,
p.Direction,
p.DbType,
p.IsNullable,
p.Size,
p.Precision,
p.Scale))
.Select(p => $"{p.Name}={p.FormatParameter()}")
.Join(),
command.CommandType,
command.CommandTimeout,
command.CommandText.TrimEnd()
);
And change RelationalStrings.RelationalLoggerExecutedCommand
to:
Executed DbCommand {{elapsed}}ms [Parameters=[{{parameters}}], {{commandType}', {{commandTimeout}} {{commandText}}
(Or simply use LoggerMessage.Define
as MVC is doing)
Which will yield a queryable log entry.
The first is EF log entry and the second one is using my code (not exactly as above since I couldn't compile the source code).
Now it is possible to query for all the queries which lasted more than x ms.
Can it please be fixed before 1.1.0?
Thanks
p.s. Please change from elapsed
to ElapsedMilliseconds
to be in sync with MVC