Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
renamed HttpContextCurrent class to CurrentHttpContext to avoid confu…
Browse files Browse the repository at this point in the history
…sion with HttpContext.Current
  • Loading branch information
liviriniu committed Apr 20, 2020
1 parent 708aad2 commit c4ae636
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
static class HttpContextCurrent
static class CurrentHttpContext
{
/// <summary>
/// Gets the <see cref="T:System.Web.HttpRequest"/> object for the current HTTP request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,24 @@ 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;

// 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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/SerilogWeb.Classic/Classic/HttpApplicationWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/SerilogWeb.Classic/SerilogWeb.Classic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<Compile Include="SerilogWebClassicLoggerConfigurationExtensions.cs" />
<Compile Include="Classic\WebRequestLoggingHandler.cs" />
<Compile Include="Classic\Enrichers\ClaimValueEnricher.cs" />
<Compile Include="Classic\Enrichers\HttpContextCurrent.cs" />
<Compile Include="Classic\Enrichers\CurrentHttpContext.cs" />
<Compile Include="Classic\Enrichers\HttpRequestClientHostIPEnricher.cs" />
<Compile Include="Classic\Enrichers\HttpRequestClientHostNameEnricher.cs" />
<Compile Include="Classic\Enrichers\HttpRequestIdEnricher.cs" />
Expand Down

0 comments on commit c4ae636

Please sign in to comment.