New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Enrich.WithProperty("PropertyName", () => ValueThatConstantlyUpdates); #829

Closed
ghuntley opened this Issue Aug 19, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@ghuntley
Copy link
Member

ghuntley commented Aug 19, 2016

See the example the code below:

Log.Logger = new LoggerConfiguration()
    .Enrich.WithProperty("ApplicationVersion", NSBundle.MainBundle.InfoDictionary[new NSString("CFBundleVersion")].ToString())
    .Enrich.WithProperty("InstallationIdentifier", UIDevice.CurrentDevice.IdentifierForVendor.AsString())
    .Enrich.WithProperty("BatteryLevel", UIDevice.CurrentDevice.BatteryLevel)
    .Enrich.WithProperty("BatteryState", UIDevice.CurrentDevice.BatteryState)
    .Enrich.WithProperty("DeviceName", UIDevice.CurrentDevice.Name)
    .Enrich.WithProperty("DeviceType", UIDevice.CurrentDevice.UserInterfaceIdiom)
    .Enrich.WithProperty("DeviceModel", UIDevice.CurrentDevice.Model)
    .Enrich.WithProperty("DeviceOrientation", UIDevice.CurrentDevice.Orientation)
    .Enrich.WithProperty("OperatingSystem", UIDevice.CurrentDevice.SystemVersion)
    .Enrich.WithProperty("NetworkConnectivity", CrossConnectivity.Current.ConnectionTypes)
  • The properties - NetworkConnectivity, DeviceOrientation, BatteryState and BatteryLevel are not constant and I'd like to have Serilog fetch the value on each log event
  • Potentially have the property enabled/disabled and remotely controllable from Seq via the existing LoggingLevelSwitch functionality on a per property basis. "ie. define battery status == debug, network connectivity == informational, deviceorientation == verbose" if there is a serious performance cost.

@ghuntley ghuntley changed the title .Enrich.WithProperty("ProperyName", () => ValueThatConstantlyUpdates); .Enrich.WithProperty("PropertyName", () => ValueThatConstantlyUpdates); Aug 19, 2016

@nblumhardt

This comment has been minimized.

Copy link
Member

nblumhardt commented Aug 19, 2016

Hi Geoffrey!

The config here will be a lot cleaner if you use:

    .Enrich.With<BatteryDetailsEnricher>()

And implement BatteryDetailsEnricher as an ILogEventEnricher adding both BatteryLevel and BatteryState.

I can see how a delegate version of WithProperty() would work, but in practice once configuration gets to this level of complexity refactoring to some enrichers will be much nicer to look at and test.

The idea of turning on/off enrichers based on level is a really interesting one, I need to give it a bit more thought, thanks!

@ghuntley

This comment has been minimized.

Copy link
Member

ghuntley commented Aug 19, 2016

Alright, sweet I'll take a look into doing proper implementations of ILogEventEnricher.

re: The idea of turning on/off enrichers based on level is a really interesting one, I need to give it a bit more thought, thanks!

Yeah, that's the thing. I'm not actually using Serilog/Seq for "text based logging" in the traditional sense, it is more of an eventstore and there are lots of events I wish to always be sent back up server side but ultimately the level of detail or what properties are attached to the event is what matters in this type of setup. Example "When verbose mode is on, send back the entire client side viewmodel and the httpresponsecontent that was used to construct that viewmodel"

@nblumhardt nblumhardt closed this Oct 14, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment