Exemplo n.º 1
0
        public void When_a_context_only_has_sensitive_information_then_only_a_sensitive_property_is_present()
        {
            using (SensitiveLogContext.PushProperty(SensitiveInformationType.FirstName, "SensitiveValue"))
                Logger.Information("Test");

            Assert.Equal(@"{""__sensitiveInfo"":{""FirstName"":""SensitiveValue""}}", Sink.Properties);
        }
Exemplo n.º 2
0
        public void When_a_context_has_both_sensitive_and_regular_information_then_both_types_are_present()
        {
            using (LogContext.PushProperty("Regular", "RegularValue"))
                using (SensitiveLogContext.PushProperty("Sensitive", "SensitiveValue"))
                    Logger.Information("Test");

            Assert.Equal(@"{""__sensitiveInfo"":{""Sensitive"":""SensitiveValue""},""Regular"":""RegularValue""}", Sink.Properties);
        }
Exemplo n.º 3
0
        public static void Run()
        {
            Log.Logger = new LoggerConfiguration()
                         .Enrich.With <MachineNameEnricher>()
                         .Enrich.FromLogContext()
                         .Enrich.With(new SensitiveInformationEnricher())
                         .WriteTo.Sink(SerilogConfiguration.CreateAzureEventHubBatchingSink())
                         .CreateLogger();

            var logger = Log.Logger.MarkAsReviewedRegardingSensitiveInformation();


            logger.ForContext("RegularProp", "regular value")
            .WithSensitiveInformation("SensitiveProp", "sensitive value")
            .Information("WithSensitiveInformation");

            using (SensitiveLogContext.PushProperty("SensitiveProp", "sensitive value"))
                using (LogContext.PushProperty("RegularProp", "regular value"))
                    logger.Information("SensitiveLogContext");

            Log.CloseAndFlush();
        }