Skip to content
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

Make MDC and MDLC Set method using friendly #2526

Closed
MikeFH opened this issue Jan 20, 2018 · 9 comments
Closed

Make MDC and MDLC Set method using friendly #2526

MikeFH opened this issue Jan 20, 2018 · 9 comments

Comments

@MikeFH
Copy link
Contributor

MikeFH commented Jan 20, 2018

Type :

  • Feature request

Why do we need it?
This would make the MDC and MDLC usage easier when the goal is to capture scoped data.
For example :

public void DoSomethingWithProduct(Product p) {
	using (MappedDiagnosticContext.Set("productId", p.Id)) {
		//do something	
	}
}

This is already present in NDC and NDLC.

I'am not sure about the performance inpact such a feature would have but if the returned IDisposable is a struct, maybe it wouldn't impact current users too much.

@304NotModified 304NotModified added enhancement Improvement on existing feature feature labels Feb 12, 2018
@304NotModified
Copy link
Member

I'am not sure about the performance inpact such a feature would have but if the returned IDisposable is a struct, maybe it wouldn't impact current users too much.

I don't think this will hurt performance

PR would be nice !

@304NotModified 304NotModified removed the enhancement Improvement on existing feature label Feb 12, 2018
@304NotModified 304NotModified added this to the 4.5 milestone Mar 7, 2018
@304NotModified
Copy link
Member

304NotModified commented Mar 7, 2018

:) merged, thanks @MikeFH !

@MikeFH
Copy link
Contributor Author

MikeFH commented Mar 7, 2018

Thanks !

@MikeFH
Copy link
Contributor Author

MikeFH commented Apr 5, 2018

@304NotModified Should I add something in the doc regarding the new methods ?

@304NotModified
Copy link
Member

Thanks for the suggestion. Where would you like to add it?

It's anyway already in the API docs, but more exposure would be nice.

@MikeFH
Copy link
Contributor Author

MikeFH commented Apr 6, 2018

I thought of adding something along the lines of

The SetScoped method returns an IDisposable that removes the added item when disposed. It can be used in conjunction with the using statement to limit the scope during which the item will be present in the context.

with a simple code example in those pages
https://github.com/NLog/NLog/wiki/MDLC-Layout-Renderer
https://github.com/NLog/NLog/wiki/MDC-Layout-Renderer

But I totally forgot about the API docs so, I agree, the need is limited.

@304NotModified
Copy link
Member

Yeah would be nice to add to the mdc and mdlc pages! please do 👍

@MikeFH
Copy link
Contributor Author

MikeFH commented Apr 6, 2018

Alright, done !

@304NotModified
Copy link
Member

thanks!!

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

No branches or pull requests

2 participants