HttpContext.Current
refers to System.Web.HttpContext
which is part of the System.Web
namespace that was used in the old ASP.NET.
ASP.NET Core does not use types within the System.Web
namespace, and anything that applied in the old ASP.NET world will need to be reevaluated whether it still works with the appropriate new types in the Microsoft.AspNetCore
namespace.
For the HttpContext
, the new type is Microsoft.AspNetCore.Http.HttpContext
. However, it does not have a IsDebuggingEnabled
property that the old type had.
The reason for this is that the old ASP.NET was an application that was running inside a web server (most commonly IIS), and that web server provided the HttpContext to the application. So you had to use HttpContext.Current
to access that context.
In ASP.NET Core however, the application includes the webserver, making ASP.NET Core applications able to run completely independent of this. Now, when debugging, instead of attaching to the parent webserver, with ASP.NET Core, you are now attaching to process of the ASP.NET Core application itself. This is also why you are usually creating command line applications (which contain the webserver with your application code). And because they are normal (command line) applications, you will have to use the standard tools to figure out whether or not the debugger is attached.
The usual way for this is to check Debugger.IsAttached
for this:
if (Debugger.IsAttached)
{
// debugger is attached
}
However, note that debuggers are not required to attach right when an application launches. It is perfectly fine to only attach the debugger later when the application is already running. This is important since the code in your Startup
or your WebHostBuilder
will only run once when the application starts. So it is possible that even with the debugger being attached, the code that registered your logging provider ran at a time where the debugger was not yet attached.