1

I have a need to send data via a sub-logger that only includes specific contextual data. In this case, I am pretty much wanting to ignore everything from the Message Template (except the text itself) and pass key contextual data already added by enrichers and PushContext statements. This is mainly to create a dashboard view that stays consistant.

LevelSwitch = new LoggingLevelSwitch { MinimumLevel = LogLevelSerilog.Verbose };

Log.Logger = new LoggerConfiguration()
.MinimumLevel.ControlledBy(LevelSwitch)
.Enrich.With<CorrelationIdEnricher>()
.Enrich.With<ThreadIdEnricher>()
.Enrich.FromLogContext()
.WriteTo.Seq("http://localhost/Response")
// Filter to a sublogger for instrumentation...
.WriteTo.Logger(lc => lc.MinimumLevel.Information()
                        .WriteTo.Seq("http://localhost/Public")
                        .Filter.ByIncludingOnly(q => q.Properties.ContainsKey("Controller") 
                                                    || q.Properties.ContainsKey("Action")
                                                    || q.Properties.ContainsKey("Class")
                                                    || q.Properties.ContainsKey("Method")
                                                    || q.Properties.ContainsKey("Organization")
                                                    || q.Properties.ContainsKey("OrganizationId")
                                                    || q.Properties.ContainsKey("CorrelationId")))
.CreateLogger();

Any ideas why this is not sending any events to the sub-logger? (Figured this out)

Any ideas why I am getting everything from the main logger (per level allowed)? I expected the filter(s) to reduce the amount of data going to the sub-logger. i.e.: I want just the filtered data to go to the sub-logger. Any added data should be stripped off of the log.

Keith Barrows
  • 24,802
  • 26
  • 88
  • 134

1 Answers1

1

The outer logger would need to have at least the Information level enabled in order for this to work - if the LevelSwitch is set at Warning or Error, this would explain the absence of events reaching the sub-logger.

Nicholas Blumhardt
  • 30,271
  • 4
  • 90
  • 101
  • Was set to Verbose. Added edit to original post to show this. – Keith Barrows Jul 07 '17 at 16:47
  • I am now getting events to the 2nd Seq instance. Turned out to be a misspelling when the instance was set up. However, the ByIncludingOnly is not behaving as expected. If any of the properties are present I am getting an exact duplicate of the main logger. I expected that all properties would be dropped except the ones in my list. – Keith Barrows Jul 07 '17 at 16:49