You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by GitBox <gi...@apache.org> on 2020/12/16 14:05:17 UTC

[GitHub] [logging-log4net] NicholasNoise commented on pull request #72: Allow DI to create instances

NicholasNoise commented on pull request #72:
URL: https://github.com/apache/logging-log4net/pull/72#issuecomment-746338377


   @fluffynuts 
   I've used custom `PatternConverter`:
   ```csharp
           /// <inheritdoc />
           protected override void Convert(TextWriter writer, object state)
           {
               if (writer == null)
                   throw new ArgumentNullException(nameof(writer));
   
               string uri = GetUri();
               writer.Write(uri);
           }
   
           private static string GetUri()
           {
   #if NETFRAMEWORK
               try
               {
                   var request = HttpContext.Current?.Request;
                   return request?.Url.AbsoluteUri;
               }
               catch (Exception)
               {
                   return null;
               }
   #elif NETSTANDARD
               return null;
   #endif
           }
   ```
   But now I'm not able to use it, cuz there are no static `HttpContext` for netstandard2.0 \ netcoreapp, so we need to inject `IHttpContextAccessor` to support this feature.


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org