I am currently trying to upgrade a logging lib from framework 4.8 to .net 6. We have the following lines of code
if (isWebApplication)
{
_URI = System.Web.HttpContext.Current.Request.ServerVariables["URL"];
}
else
{
_URI = My.Computer.Info.OSFullName;
}
which I am struggeling to get working again since the System.Web.HttpContext does not exist in this form anymore.
The only way to get the URL is form an existing request object, but since the logging lib should not care if it is used in a web or desktop app, I cant expect a HttpRequest object.
Are there any other generic ways to solve this?
EDIT: The library is used in this way in multiple applications already which are planned to be updated or EOL in the near of far future, so a rewrite to a less "smart" version is not an option.
HttpContext.Currentwas one of the very first things removed in ASP.NET Core 1.0. This change is addressed in all docs going back to .NET Core 1.0 and numerous blog postsupgrade a logging lib.NET Core has a built-in logging system used by all libraries. All popular logging libraries like Serilog and NLog already integrate with it. Check for example Serilog's ASP.NET Core integration