public async Task Logs_commands_parameter_values( Delegate commandDelegate, string diagnosticName, bool async) { var optionsExtension = new FakeRelationalOptionsExtension().WithConnectionString(ConnectionString); var options = CreateOptions(optionsExtension); var logFactory = new ListLoggerFactory(); var fakeConnection = new FakeRelationalConnection(options); var logger = new DiagnosticsLogger <DbLoggerCategory.Database.Command>( logFactory, new FakeLoggingOptions(true), new DiagnosticListener("Fake"), new TestRelationalLoggingDefinitions()); var relationalCommand = CreateRelationalCommand( commandText: "Logged Command", parameters: new[] { new TypeMappedRelationalParameter( "FirstInvariant", "FirstParameter", new IntTypeMapping("int", DbType.Int32), false) }); var parameterValues = new Dictionary <string, object> { { "FirstInvariant", 17 } }; if (async) { await((CommandFunc)commandDelegate)(fakeConnection, relationalCommand, parameterValues, logger); } else { ((CommandAction)commandDelegate)(fakeConnection, relationalCommand, parameterValues, logger); } Assert.Equal(5, logFactory.Log.Count); Assert.Equal(LogLevel.Debug, logFactory.Log[0].Level); Assert.Equal(LogLevel.Debug, logFactory.Log[1].Level); Assert.Equal(LogLevel.Warning, logFactory.Log[2].Level); Assert.Equal( CoreResources.LogSensitiveDataLoggingEnabled(new TestLogger <TestRelationalLoggingDefinitions>()).GenerateMessage(), logFactory.Log[2].Message); Assert.Equal(LogLevel.Information, logFactory.Log[3].Level); Assert.Equal(LogLevel.Debug, logFactory.Log[4].Level); foreach (var(_, _, message, _, _) in logFactory.Log.Skip(3)) { Assert.EndsWith( "[Parameters=[FirstParameter='17'], CommandType='0', CommandTimeout='30']" + _eol + "Logged Command", message); } }
public virtual void Queryable_with_parameter_outputs_parameter_value_logging_warning() { using var context = CreateContext(); context.GetInfrastructure().GetRequiredService <IDiagnosticsLogger <DbLoggerCategory.Query> >() .Options.IsSensitiveDataLoggingWarned = false; // ReSharper disable once ConvertToConstant.Local var city = "Redmond"; var customers = context.Customers .Where(c => c.City == city) .ToList(); Assert.NotNull(customers); Assert.Contains( CoreResources.LogSensitiveDataLoggingEnabled(new TestLogger <SqlServerLoggingDefinitions>()).GenerateMessage(), Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message)); }
public virtual void Queryable_with_parameter_outputs_parameter_value_logging_warning() { using var context = CreateContext(); context.GetInfrastructure().GetRequiredService <IDiagnosticsLogger <DbLoggerCategory.Query> >() .Options.IsSensitiveDataLoggingWarned = false; // ReSharper disable once ConvertToConstant.Local var city = "Redmond"; var customers = context.Customers .Where(c => c.City == city) .ToList(); Assert.NotNull(customers); if (ExpectSensitiveData) { Assert.Contains( CoreResources.LogSensitiveDataLoggingEnabled(new TestLogger <CosmosLoggingDefinitions>()).GenerateMessage(), Fixture.TestSqlLoggerFactory.Log.Select(l => l.Message)); } if (ExpectSensitiveData) { Assert.Equal( CosmosResources.LogExecutingSqlQuery(new TestLogger <CosmosLoggingDefinitions>()).GenerateMessage( "NorthwindContext", "(null)", "@__city_0='Redmond'", Environment.NewLine, @"SELECT c FROM root c WHERE ((c[""Discriminator""] = ""Customer"") AND (c[""City""] = @__city_0))"), Fixture.TestSqlLoggerFactory.Log[3].Message); } else { Assert.Equal( CosmosResources.LogExecutingSqlQuery(new TestLogger <CosmosLoggingDefinitions>()).GenerateMessage( "NorthwindContext", "?", "@__city_0=?", Environment.NewLine, @"SELECT c FROM root c WHERE ((c[""Discriminator""] = ""Customer"") AND (c[""City""] = @__city_0))"), Fixture.TestSqlLoggerFactory.Log[2].Message); } }