fluffynuts commented on code in PR #365:
URL: https://github.com/apache/logging-log4net/pull/365#discussion_r4639160175


##########
src/log4net/Layout/Pattern/AspNetPatternLayoutConverter.cs:
##########
@@ -26,25 +26,40 @@
 namespace log4net.Layout.Pattern;
 
 /// <summary>
-/// Abstract class that provides access to the current HttpContext (<see 
cref="HttpContext.Current" />) that 
-/// derived classes need.
+/// Base of the <c>%aspnet-*</c> converters; writes <see 
cref="SystemInfo.NotAvailableText" /> without a current request.
 /// </summary>
 /// <remarks>
-/// This class handles the case when HttpContext.Current is null by writing
-/// <see cref="SystemInfo.NotAvailableText" /> to the writer.
+/// A request scoped converter also writes it for an event fixed with 
properties in another request.
 /// </remarks>
 /// <author>Ron Grabowski</author>
 internal abstract class AspNetPatternLayoutConverter : PatternLayoutConverter
 {
+  private readonly bool _isRequestScoped;
+
+  /// <summary>
+  /// Registers the request capture for a converter that shows request data.
+  /// </summary>
+  /// <param name="isRequestScoped">Whether the converter shows data of the 
current request, not of the application.</param>
+  protected AspNetPatternLayoutConverter(bool isRequestScoped)
+  {
+    _isRequestScoped = isRequestScoped;
+    if (isRequestScoped)
+    {
+      AspNetRequestCapture.Register();
+    }
+  }
+
   protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
   {
-    if (HttpContext.Current is null)
+    // Another request's data would be wrong, not missing.

Review Comment:
   minor: `request` is a misleading var name here - http context would have a 
request and response object on it; suggest `ctx` or `httpContext`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to