Open michasacuer opened 1 year ago
Nothing on this yet?
Might be because you are using Sdk.Worker as project instead of Sdk.Web
I'm using <PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.35" />
Because my app works with Microsoft.Azure.WebJobs
In my program.cs
hostBuilder.ConfigureLogging((context, loggingBuilder) =>
{
loggingBuilder.AddApplicationInsightsWebJobs();
});
It saddens me to see, that Microsoft has not prioritized this to be fixed as of yet. I mean, IHostingEnvironment
was marked obsolete with the release of .NET 3. Now, 4 versions later, this has still not been fixed.
I would suggest you to make an extension method like this:
public static IHostBuilder AddBackwardCompatibleHostingEnvironment(this IHostBuilder host)
{
return host.ConfigureServices((context, services) =>
{
services.AddSingleton<Microsoft.AspNetCore.Hosting.IHostingEnvironment>(provider =>
{
var env = provider.GetRequiredService<IWebHostEnvironment>();
return new BackwardCompatibleHostingEnvironment()
{
EnvironmentName = env.EnvironmentName,
ApplicationName = env.ApplicationName,
ContentRootPath = env.ContentRootPath,
WebRootPath = env.WebRootPath,
WebRootFileProvider = env.WebRootFileProvider,
ContentRootFileProvider = env.ContentRootFileProvider
};
});
});
}
Where the BackwardCompatibleHostingEnvironment
would be an internal class used solely for this purpose:
internal class BackwardCompatibleHostingEnvironment : Microsoft.AspNetCore.Hosting.IHostingEnvironment
{
public BackwardCompatibleHostingEnvironment()
{
}
public string EnvironmentName { get; set; }
public string ApplicationName { get; set; }
public string WebRootPath { get; set; }
public IFileProvider WebRootFileProvider { get; set; }
public string ContentRootPath { get; set; }
public IFileProvider ContentRootFileProvider { get; set; }
}
I do hope someone from Microsoft is reading along the lines. Give us a proper version no longer relying on retired products. It should not be that difficult ..
Just ran into the same issue and found this to be a solution. It's honestly ridiculous that the issue popped up already several years ago and still not fixed.
Running stuff in azure the app insights is quite sensible way to get telemetry/traces out, but this make one really really really want to integrate to the service, when willing to go through this :(
*.csproj
file): net7.0Describe the bug
I can not use
IHostApplicationLifetime
interface while i registerservices.AddApplicationInsightsTelemetry();
method.To Reproduce
my csproj file:
And my
Program.cs
class:Here is the stacktrace:
And Worker.cs class: