'logs messages not showing in application insights application for worker service
This is my Program.Cs class
public static void Main(string[] args)
enter code here{
var services = new ServiceCollection();
var configuration = GetConfiguration(args);
var serviceProvider = services
.AddSingleton(configuration)
.AddLogging(builder => builder
.AddConsole()
.AddFilter<ApplicationInsightsLoggerProvider>("Category", LogLevel.Information))
.BuildServiceProvider();
IHost host = Host.CreateDefaultBuilder(args)
.UseWindowsService()
.ConfigureServices((hostcontext, serviceProvider) =>
{
serviceProvider.AddHostedService<Program>();
serviceProvider.AddApplicationInsightsTelemetryWorkerService();// add instrumentation key
})
.Build();
host.Run();
}
This is my main service class
protected async Task OnStart(string[] args)
{
_logger.LogInformation("start");
using (var getDetailsOperation = _telemetryClient.StartOperation<RequestTelemetry>("operation"))
{
try
{
this._telemetryClient.TrackTrace("start!!!");
//my code
_logger.LogInformation("Starting service ...");
}
catch(Exception ex){
_logger.LogError(ex, OnStart - Exception Thrown");
this._telemetryClient.TrackTrace("Error !!!!!!!!!");
}
}
}
I want to log message for another classes also. Please help me out.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
