-
Notifications
You must be signed in to change notification settings - Fork 165
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
Fix possible deadlock issue with AspNetLayoutRendererBase.Register #632
Comments
Could at the same time suppress |
We need to change things in NLog for this.
Another option is to copy FuncLayoutRenderer, but then you're missing IStringValueRenderer for example and coping code is never really nice (e.g. FormatAsJson) Also...
|
I prefer just to make an internal class in Nlog.Web that takes the input method as constructor parameter.
|
Yes, but we still need the changes in NLog itself ;) |
Why?
|
Maybe something like this (if you think FunctionLayoutRenderer is the best thing): internal class NLogWebLayoutRenderer : FunctionLayoutRenderer
{
Func<LogEventInfo, HttpContextBase, LoggingConfiguration, object> _func;
private IHttpContextAccessor HttpContextAccessor { get; set; } // TODO Missing implementation
public NLogWebLayoutRenderer(string name, Func<LogEventInfo, HttpContextBase, LoggingConfiguration, object> func)
:base(name, (event, config) => LookupValue(event, config))
{
_func = func;
}
private object LookupValue(LogEventInfo logEvent, LoggingConfiguration config)
{
var httpContext = HttpContextAccessor?.HttpContext;
return _func(logEvent, httpContext, config);
}
} Alternative one could have FunctionLayoutRenderer as a member an initialize it when needing it, and instead inherit from AspNetLayoutRendererBase (And get HttpContextAccessor for free) |
I will look into this :) |
LookupValue needs to be static then (and so also HttpContextAccessor property). And I don't think we like static "cache" If static is ok, we could add it to the AspNetLayoutRendererBase. But that doesn't look right |
Then I guess FunctionLayoutRenderer has to be improved, by adding a new protected virtual method called RenderValue() that returns object (Think messing with RenderMethod-property is a mistake). And at some point this special implementation of FunctionLayoutRenderer will use |
yes indeed, see NLog/NLog#4326 :) |
working on this --> #659 |
RetrieveHttpContextAccessor
is a dangerous method, and should not be called frequently, because it can introduce deadlocks. See also: NLog/NLog#2064Instead one should create a new class
FuncAspNetLayoutRenderer
, that can hold the func-delegate and perform caching ofHttpContextAccessor
.The text was updated successfully, but these errors were encountered: