0

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.

12
  • If the logging library should be oblivious of its consumers, then, it shouldn't take hard dependencies or make assumptions like above either. Callers should provide this contextual data or inject some object which wraps access to this. Commented Apr 25, 2024 at 11:31
  • As I said, I am updating this lib to a new .net version. I am not trying to build a new (better) version of it. It should be useable just like the old one. Commented Apr 25, 2024 at 11:33
  • .NET 6 is .NET Core 6. The singleton HttpContext.Current was 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 posts Commented Apr 25, 2024 at 11:34
  • @dturnschek you aren't updating to a new .NET version, you're moving to a completely different platform. upgrade 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 Commented Apr 25, 2024 at 11:37
  • Besides, logging the request URL isn't the job of the logging library, it's the job of ASP.NET Core. ASP.NET Core already emits log events for requests including the URL as an attribute, using the ILogger middleware. Log targets like Serilog or the Console write the events to files, the console, Elastic etc based on their configuration. They don't care where that tag came from Commented Apr 25, 2024 at 11:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.