예제 #1
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static void ExecutingReadItem(
            this IDiagnosticsLogger <DbLoggerCategory.Database.Command> diagnostics,
            string containerId,
            string?partitionKey,
            string resourceId)
        {
            var definition = CosmosResources.LogExecutingReadItem(diagnostics);

            if (diagnostics.ShouldLog(definition))
            {
                var logSensitiveData = diagnostics.ShouldLogSensitiveData();
                definition.Log(diagnostics, logSensitiveData ? resourceId : "?", containerId, logSensitiveData ? partitionKey : "?");
            }

            if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
            {
                var eventData = new CosmosReadItemEventData(
                    definition,
                    ExecutingReadItem,
                    resourceId,
                    containerId,
                    partitionKey,
                    diagnostics.ShouldLogSensitiveData());

                diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
            }
        }
예제 #2
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static void ExecutingSqlQuery(
            this IDiagnosticsLogger <DbLoggerCategory.Database.Command> diagnostics,
            string containerId,
            string?partitionKey,
            CosmosSqlQuery cosmosSqlQuery)
        {
            var definition = CosmosResources.LogExecutingSqlQuery(diagnostics);

            if (diagnostics.ShouldLog(definition))
            {
                var logSensitiveData = diagnostics.ShouldLogSensitiveData();

                definition.Log(
                    diagnostics,
                    containerId,
                    logSensitiveData ? partitionKey : "?",
                    FormatParameters(cosmosSqlQuery.Parameters, logSensitiveData && cosmosSqlQuery.Parameters.Count > 0),
                    Environment.NewLine,
                    cosmosSqlQuery.Query);
            }

            if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
            {
                var eventData = new CosmosQueryEventData(
                    definition,
                    ExecutingSqlQuery,
                    containerId,
                    partitionKey,
                    cosmosSqlQuery.Parameters.Select(p => (p.Name, p.Value)).ToList(),
                    cosmosSqlQuery.Query,
                    diagnostics.ShouldLogSensitiveData());

                diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
            }
        }
예제 #3
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static void ExecutedReadNext(
            this IDiagnosticsLogger <DbLoggerCategory.Database.Command> diagnostics,
            TimeSpan elapsed,
            double requestCharge,
            string activityId,
            string containerId,
            string?partitionKey,
            CosmosSqlQuery cosmosSqlQuery)
        {
            var definition = CosmosResources.LogExecutedReadNext(diagnostics);

            if (diagnostics.ShouldLog(definition))
            {
                var logSensitiveData = diagnostics.ShouldLogSensitiveData();

                definition.Log(
                    diagnostics,
                    l => l.Log(
                        definition.Level,
                        definition.EventId,
                        definition.MessageFormat,
                        elapsed.TotalMilliseconds,
                        requestCharge,
                        activityId,
                        containerId,
                        logSensitiveData ? partitionKey : "?",
                        FormatParameters(cosmosSqlQuery.Parameters, logSensitiveData && cosmosSqlQuery.Parameters.Count > 0),
                        Environment.NewLine,
                        cosmosSqlQuery.Query));
            }

            if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
            {
                var eventData = new CosmosQueryExecutedEventData(
                    definition,
                    ExecutedReadNext,
                    elapsed,
                    requestCharge,
                    activityId,
                    containerId,
                    partitionKey,
                    cosmosSqlQuery.Parameters.Select(p => (p.Name, p.Value)).ToList(),
                    cosmosSqlQuery.Query,
                    diagnostics.ShouldLogSensitiveData());

                diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
            }
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        /// <summary>
        ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to
        ///     the same compatibility standards as public APIs. It may be changed or removed without notice in
        ///     any release. You should only use it directly in your code with extreme caution and knowing that
        ///     doing so can result in application failures when updating to a new Entity Framework Core release.
        /// </summary>
        public static void ExecutedReplaceItem(
            this IDiagnosticsLogger <DbLoggerCategory.Database.Command> diagnostics,
            TimeSpan elapsed,
            double requestCharge,
            string activityId,
            string resourceId,
            string containerId,
            string?partitionKey)
        {
            var definition = CosmosResources.LogExecutedReplaceItem(diagnostics);

            if (diagnostics.ShouldLog(definition))
            {
                var logSensitiveData = diagnostics.ShouldLogSensitiveData();
                definition.Log(
                    diagnostics,
                    elapsed.TotalMilliseconds.ToString(),
                    requestCharge.ToString(),
                    activityId,
                    containerId,
                    logSensitiveData ? resourceId : "?",
                    logSensitiveData ? partitionKey : "?");
            }

            if (diagnostics.NeedsEventData(definition, out var diagnosticSourceEnabled, out var simpleLogEnabled))
            {
                var eventData = new CosmosItemCommandExecutedEventData(
                    definition,
                    ExecutedReplaceItem,
                    elapsed,
                    requestCharge,
                    activityId,
                    containerId,
                    resourceId,
                    partitionKey,
                    diagnostics.ShouldLogSensitiveData());

                diagnostics.DispatchEventData(definition, eventData, diagnosticSourceEnabled, simpleLogEnabled);
            }
        }
예제 #6
0
        public virtual void Queryable_simple()
        {
            using var context = CreateContext();
            var customers
                = context.Set <Customer>()
                  .ToList();

            Assert.NotNull(customers);

            Assert.StartsWith(
                "Compiling query expression: ",
                Fixture.TestSqlLoggerFactory.Log[0].Message);

            Assert.StartsWith(
                "Generated query execution expression: " + Environment.NewLine + "'queryContext => new QueryingEnumerable<Customer>(",
                Fixture.TestSqlLoggerFactory.Log[1].Message);

            if (ExpectSensitiveData)
            {
                Assert.Equal(
                    CosmosResources.LogExecutingSqlQuery(new TestLogger <CosmosLoggingDefinitions>()).GenerateMessage(
                        "NorthwindContext", "(null)", "", Environment.NewLine,
                        @"SELECT c
FROM root c
WHERE (c[""Discriminator""] = ""Customer"")"),
                    Fixture.TestSqlLoggerFactory.Log[2].Message);
            }
            else
            {
                Assert.Equal(
                    CosmosResources.LogExecutingSqlQuery(new TestLogger <CosmosLoggingDefinitions>()).GenerateMessage(
                        "NorthwindContext", "?", "", Environment.NewLine,
                        @"SELECT c
FROM root c
WHERE (c[""Discriminator""] = ""Customer"")"),
                    Fixture.TestSqlLoggerFactory.Log[2].Message);
            }
        }