From c4ae6364598aac795c78a186755a8017ccd4a970 Mon Sep 17 00:00:00 2001 From: liviriniu Date: Mon, 20 Apr 2020 16:40:53 +0300 Subject: [PATCH] renamed HttpContextCurrent class to CurrentHttpContext to avoid confusion with HttpContext.Current --- .../Classic/Enrichers/ClaimValueEnricher.cs | 2 +- .../{HttpContextCurrent.cs => CurrentHttpContext.cs} | 2 +- .../Enrichers/HttpRequestClientHostIPEnricher.cs | 12 ++++++------ .../Enrichers/HttpRequestClientHostNameEnricher.cs | 6 +++--- .../Classic/Enrichers/HttpRequestRawUrlEnricher.cs | 6 +++--- .../Classic/Enrichers/HttpRequestTypeEnricher.cs | 6 +++--- .../Classic/Enrichers/HttpRequestUrlEnricher.cs | 4 ++-- .../Enrichers/HttpRequestUrlReferrerEnricher.cs | 6 +++--- .../Enrichers/HttpRequestUserAgentEnricher.cs | 6 +++--- .../Classic/HttpApplicationWrapper.cs | 2 +- src/SerilogWeb.Classic/SerilogWeb.Classic.csproj | 2 +- 11 files changed, 27 insertions(+), 27 deletions(-) rename src/SerilogWeb.Classic/Classic/Enrichers/{HttpContextCurrent.cs => CurrentHttpContext.cs} (97%) diff --git a/src/SerilogWeb.Classic/Classic/Enrichers/ClaimValueEnricher.cs b/src/SerilogWeb.Classic/Classic/Enrichers/ClaimValueEnricher.cs index 0960b2b..12aa97e 100644 --- a/src/SerilogWeb.Classic/Classic/Enrichers/ClaimValueEnricher.cs +++ b/src/SerilogWeb.Classic/Classic/Enrichers/ClaimValueEnricher.cs @@ -70,7 +70,7 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) if (HttpContext.Current == null) return; - if (HttpContextCurrent.Request == null) + if (CurrentHttpContext.Request == null) return; var user = HttpContext.Current.User; diff --git a/src/SerilogWeb.Classic/Classic/Enrichers/HttpContextCurrent.cs b/src/SerilogWeb.Classic/Classic/Enrichers/CurrentHttpContext.cs similarity index 97% rename from src/SerilogWeb.Classic/Classic/Enrichers/HttpContextCurrent.cs rename to src/SerilogWeb.Classic/Classic/Enrichers/CurrentHttpContext.cs index 6611f95..54f3814 100644 --- a/src/SerilogWeb.Classic/Classic/Enrichers/HttpContextCurrent.cs +++ b/src/SerilogWeb.Classic/Classic/Enrichers/CurrentHttpContext.cs @@ -7,7 +7,7 @@ namespace SerilogWeb.Classic.Enrichers /// This helper class is used to handle special case introduced by ASP.NET integrated pipeline /// when HttpContextCurrent.Request may throw instead of returning null. /// - static class HttpContextCurrent + static class CurrentHttpContext { /// /// Gets the object for the current HTTP request. diff --git a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestClientHostIPEnricher.cs b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestClientHostIPEnricher.cs index bdde046..9aea12d 100644 --- a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestClientHostIPEnricher.cs +++ b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestClientHostIPEnricher.cs @@ -71,10 +71,10 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) if (HttpContext.Current == null) return; - if (HttpContextCurrent.Request == null) + if (CurrentHttpContext.Request == null) return; - if (string.IsNullOrWhiteSpace(HttpContextCurrent.Request.UserHostAddress)) + if (string.IsNullOrWhiteSpace(CurrentHttpContext.Request.UserHostAddress)) return; string userHostAddress; @@ -82,13 +82,13 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) // Taking Proxy/-ies into consideration, too (if wanted and available) if (CheckForHttpProxies) { - userHostAddress = !string.IsNullOrWhiteSpace(HttpContextCurrent.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]) - ? HttpContextCurrent.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] - : HttpContextCurrent.Request.UserHostAddress; + userHostAddress = !string.IsNullOrWhiteSpace(CurrentHttpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]) + ? CurrentHttpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] + : CurrentHttpContext.Request.UserHostAddress; } else { - userHostAddress = HttpContextCurrent.Request.UserHostAddress; + userHostAddress = CurrentHttpContext.Request.UserHostAddress; } if (string.IsNullOrWhiteSpace(userHostAddress)) diff --git a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestClientHostNameEnricher.cs b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestClientHostNameEnricher.cs index 4f10eac..8c334fc 100644 --- a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestClientHostNameEnricher.cs +++ b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestClientHostNameEnricher.cs @@ -39,13 +39,13 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { if (logEvent == null) throw new ArgumentNullException("logEvent"); - if (HttpContextCurrent.Request == null) + if (CurrentHttpContext.Request == null) return; - if (string.IsNullOrWhiteSpace(HttpContextCurrent.Request.UserHostName)) + if (string.IsNullOrWhiteSpace(CurrentHttpContext.Request.UserHostName)) return; - var userHostName = HttpContextCurrent.Request.UserHostName; + var userHostName = CurrentHttpContext.Request.UserHostName; var httpRequestClientHostnameProperty = new LogEventProperty(HttpRequestClientHostNamePropertyName, new ScalarValue(userHostName)); logEvent.AddPropertyIfAbsent(httpRequestClientHostnameProperty); } diff --git a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestRawUrlEnricher.cs b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestRawUrlEnricher.cs index fec76b5..e249029 100644 --- a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestRawUrlEnricher.cs +++ b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestRawUrlEnricher.cs @@ -43,13 +43,13 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) if (HttpContext.Current == null) return; - if (HttpContextCurrent.Request == null) + if (CurrentHttpContext.Request == null) return; - if (string.IsNullOrWhiteSpace(HttpContextCurrent.Request.RawUrl)) + if (string.IsNullOrWhiteSpace(CurrentHttpContext.Request.RawUrl)) return; - var requestRawUrl = HttpContextCurrent.Request.RawUrl; + var requestRawUrl = CurrentHttpContext.Request.RawUrl; var httpRequestRawUrlProperty = new LogEventProperty(HttpRequestRawUrlPropertyName, new ScalarValue(requestRawUrl)); logEvent.AddPropertyIfAbsent(httpRequestRawUrlProperty); } diff --git a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestTypeEnricher.cs b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestTypeEnricher.cs index 3193309..5c532f2 100644 --- a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestTypeEnricher.cs +++ b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestTypeEnricher.cs @@ -43,13 +43,13 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) if (HttpContext.Current == null) return; - if (HttpContextCurrent.Request == null) + if (CurrentHttpContext.Request == null) return; - if (string.IsNullOrWhiteSpace(HttpContextCurrent.Request.RequestType)) + if (string.IsNullOrWhiteSpace(CurrentHttpContext.Request.RequestType)) return; - var requestType = HttpContextCurrent.Request.RequestType; + var requestType = CurrentHttpContext.Request.RequestType; var httpRequestTypeProperty = new LogEventProperty(HttpRequestTypePropertyName, new ScalarValue(requestType)); logEvent.AddPropertyIfAbsent(httpRequestTypeProperty); } diff --git a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestUrlEnricher.cs b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestUrlEnricher.cs index c27ce82..d550810 100644 --- a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestUrlEnricher.cs +++ b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestUrlEnricher.cs @@ -40,10 +40,10 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { if (logEvent == null) throw new ArgumentNullException("logEvent"); - if (HttpContextCurrent.Request?.Url == null) + if (CurrentHttpContext.Request?.Url == null) return; - var requestUrl = HttpContextCurrent.Request.Url.ToString(); + var requestUrl = CurrentHttpContext.Request.Url.ToString(); var httpRequestUrlProperty = new LogEventProperty(HttpRequestUrlPropertyName, new ScalarValue(requestUrl)); logEvent.AddPropertyIfAbsent(httpRequestUrlProperty); } diff --git a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestUrlReferrerEnricher.cs b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestUrlReferrerEnricher.cs index 3449acd..d2c76c7 100644 --- a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestUrlReferrerEnricher.cs +++ b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestUrlReferrerEnricher.cs @@ -43,13 +43,13 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) if (HttpContext.Current == null) return; - if (HttpContextCurrent.Request == null) + if (CurrentHttpContext.Request == null) return; - if (HttpContextCurrent.Request.UrlReferrer == null) + if (CurrentHttpContext.Request.UrlReferrer == null) return; - var requestUrlReferrer = HttpContextCurrent.Request.UrlReferrer.ToString(); + var requestUrlReferrer = CurrentHttpContext.Request.UrlReferrer.ToString(); var httpRequestUrlReferrerProperty = new LogEventProperty(HttpRequestUrlReferrerPropertyName, new ScalarValue(requestUrlReferrer)); logEvent.AddPropertyIfAbsent(httpRequestUrlReferrerProperty); } diff --git a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestUserAgentEnricher.cs b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestUserAgentEnricher.cs index f49a94d..c1fa51a 100644 --- a/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestUserAgentEnricher.cs +++ b/src/SerilogWeb.Classic/Classic/Enrichers/HttpRequestUserAgentEnricher.cs @@ -40,13 +40,13 @@ public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { if (logEvent == null) throw new ArgumentNullException("logEvent"); - if (HttpContextCurrent.Request == null) + if (CurrentHttpContext.Request == null) return; - if (string.IsNullOrWhiteSpace(HttpContextCurrent.Request.UserAgent)) + if (string.IsNullOrWhiteSpace(CurrentHttpContext.Request.UserAgent)) return; - var userAgent = HttpContextCurrent.Request.UserAgent; + var userAgent = CurrentHttpContext.Request.UserAgent; var httpRequestUserAgentProperty = new LogEventProperty(HttpRequestUserAgentPropertyName, new ScalarValue(userAgent)); logEvent.AddPropertyIfAbsent(httpRequestUserAgentProperty); } diff --git a/src/SerilogWeb.Classic/Classic/HttpApplicationWrapper.cs b/src/SerilogWeb.Classic/Classic/HttpApplicationWrapper.cs index d093416..ea61f88 100644 --- a/src/SerilogWeb.Classic/Classic/HttpApplicationWrapper.cs +++ b/src/SerilogWeb.Classic/Classic/HttpApplicationWrapper.cs @@ -26,7 +26,7 @@ public HttpRequestBase Request { get { - var req = HttpContextCurrent.Request; + var req = CurrentHttpContext.Request; if (req == null) return null; return new HttpRequestWrapper(req); } diff --git a/src/SerilogWeb.Classic/SerilogWeb.Classic.csproj b/src/SerilogWeb.Classic/SerilogWeb.Classic.csproj index 7bdcfee..8b9107b 100644 --- a/src/SerilogWeb.Classic/SerilogWeb.Classic.csproj +++ b/src/SerilogWeb.Classic/SerilogWeb.Classic.csproj @@ -59,7 +59,7 @@ - +