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

Add TraceIdentifier for ASP.Net Core #92

Closed
luciusli opened this issue Feb 2, 2017 · 4 comments
Closed

Add TraceIdentifier for ASP.Net Core #92

luciusli opened this issue Feb 2, 2017 · 4 comments
Labels
Milestone

Comments

@luciusli
Copy link

luciusli commented Feb 2, 2017

I have a middleware that add a HTTP response header with the value of HttpContext.TraceIdentifier. It would be really useful if I could log the corresponding TraceIdentifier to find out what went wrong in case of errors. Thank you.

@304NotModified
Copy link
Member

Do you have the c# code to read the TraceIdentifier in .NET Core?

@luciusli
Copy link
Author

luciusli commented Feb 3, 2017

Something like this

[LayoutRenderer("aspnet-traceidentifier")]
public class AspNetTraceIdentifierLayoutRenderer : AspNetLayoutRendererBase
{
    protected override void DoAppend(StringBuilder builder, LogEventInfo logEvent)
    {
        var context = HttpContextAccessor.HttpContext;

        builder.Append(context.TraceIdentifier);
    }
}

@304NotModified
Copy link
Member

if this works, please create a PR :)

(and or support ASP.NET 4 or exclude with #if)

@304NotModified
Copy link
Member

Added in 4.3.1! Thanks for the code!

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

No branches or pull requests

2 participants