A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/serilog-web/classic/issues/67 below:

HttpRequestUrlEnricher gives "Request is not available in this context" exception · Issue #67 · serilog-web/classic · GitHub

I am currently using SerilogWeb.Classic v5.0.56 in a legacy webforms website.
After I decided to enable SelfLog, I found that adding log entries from the Application_Start in Global.asax while enriching with HttpRequestUrl chained to new LoggerConfiguration() throws the following exception

2020-04-17T16:29:46.1743072Z Exception System.Web.HttpException (0x80004005): Request is not available in this context
   at System.Web.HttpContext.get_Request()
   at SerilogWeb.Classic.Enrichers.HttpRequestUrlEnricher.Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
   at Serilog.Core.Enrichers.SafeAggregateEnricher.Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) caught while enriching Serilog.Events.LogEvent with SerilogWeb.Classic.Enrichers.HttpRequestUrlEnricher.

'This well known exception raises its fancy head again', I told myself. So, I've looked into HttpContextCurrent.cs and HttpRequestUrlEnricher.cs.

I think that replacing if (HttpContext.Current?.Request?.Url == null) with if (HttpContextCurrent.Request?.Url == null) would fix it.

I am new to github. If I make mistakes please forgive a newbie, I'm learning/discovering :)

PS: Also I looked through the other files in the project and found no other instance of Request being accessed outside project's HttpContextCurrent. I was thinking of renaming this to help against any future confusion with HttpContext.Current.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4