nblumhardt / serilog-timings

Extends Serilog with support for timed operations
Apache License 2.0
218 stars 22 forks source link

Added support for enriching the Completed Operation log event #10

Closed benfoster closed 4 years ago

benfoster commented 8 years ago

Ref #8.

This update allows one or more LogEventEnricher instances to be passed to Operation.Complete in order to enrich the final log event.

An example of where this can be used is logging the input parameters and response content in a Web API action filter.

During ActionExecuting we begin the operation and enrich it with properties from the input parameters. It is then stored in HttpRequestMessage.Properties.

During ActionExecuted we obtain the Operation and call Complete enriching it with properties from HttpResponseMessage.Content.

nblumhardt commented 8 years ago

Thanks for the PR, this is an interesting scenario. I need to give this one a bit of thought :+1:

nblumhardt commented 8 years ago

(Sorry, wrong window)

benfoster commented 8 years ago

Alternatively a way to provide multiple result properties (not enrichers) would work for us here.

nblumhardt commented 8 years ago

Thanks for the info. I was wondering about something like:

op.AddProperty("Foo", foo);

I.e. add multiple properties to be attached to the operation throughout, perhaps allowing various bits and pieces of data to be collected.

benfoster commented 8 years ago

Yes this would would work well. FWIW, I wish Serilog had a similar API. I think it's a little confusing that you call ForContext to set the Source Context and use the same method to add properties/enrichers.

nblumhardt commented 8 years ago

:+1: yes, it's a bit awkward, I'm hopeful a better pattern will emerge as well.

ben-foster-cko commented 8 years ago

Any further thoughts on this @nblumhardt?

nblumhardt commented 8 years ago

Sorry Ben, has been a busy couple of weeks :-)

I think we could do the AddProperty(string, object, bool = false) API. Sounds like a way to move it forward?

ben-foster-cko commented 8 years ago

sounds good - would you like me to implement. Also are you happy for me to make this chainable i.e. .AddProperty(...).AddProperty(...)?

nblumhardt commented 8 years ago

Hi Ben - an implementation would be really great, thanks. I'm okay with making it chainable - happy to go with whatever you prefer.

Cheers, Nick

nblumhardt commented 4 years ago

Hey Ben! Hope all is well in your neck of the woods. I just stumbled across this one, I think it's stale now, so closing, but let me know if you want to pick it up again in the future :-) .. Cheers!