-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
How to get the Request Properties like RequestPath and RequestDetail in a class file, update it and add them back to the logs #5521
Comments
Hi! Thanks for opening your first issue here! Please make sure to follow the issue template - so we could help you better! |
When troubleshooting NLog then it is a good idea to enable If the existing layout-renderers are not doing what you want, then you can create your own custom layout-renderer: NLog.LogManager.Setup().RegisterNLogWeb().SetupExtensions(ext =>
ext.RegisterAspNetLayoutRenderer("test-web", (logEventInfo, httpContext, loggingConfiguration) =>
{
return httpContext.Session["SessionItem"];
})
); |
Thanks, snakefoot. |
If "dynamic variable" then you mean NLog Configuration Variables (Ex. Maybe consider using the NLog ScopeContext, where the class-library can provide its own custom context, and then have fallback when none provided.
Then the class library can do this: using (NLog.ScopeContext.PushProperty("RequestPath", "My Request"))
{
Logger.Info("Hello World"); // LogEvent can use ${scopeProperty:RequestPath} in target output
} Alternative you can also provide additional details using LogEvent properties for example using structured logging: Logger.Info("Hello from {RequestDetail}", "My Detail"); |
@snakefoot |
Without any hints of what you are trying, and the results you see, then it is hard to help. When troubleshooting NLog then it is a good idea to enable |
Closing due to inactivity. |
Hi! Thanks for reporting this bug!
Please keep / fill in the relevant info from this template so that we can help you as best as possible.
NLog version: (e.g. 5.2.7)
Platform: . .NET6
Current NLog config (xml or C#, if relevant): xml
My config details included have been blanked out so adding it again.
Hi,
I am new to Nlog and still learning, I have a question that I am struggling with from past couple of days.
My nlog.config looks something like this.
Question - I would like to read the Request details like RequestPath and RequestDetail in my .Net 6.0 class library class file, change it and update the lvalues back to the ogs after making an api call.
The log level is info.
All these fields show in the logs which would like to read and update.
can you please let me know how I can do this in c# and if any changes are needed to the config file?
Thanks
The text was updated successfully, but these errors were encountered: