Reputation: 60841
I'm not seeing any logging going into my application insights instance.
I have a windows service with an older version of .net core.
I have added these two libraries:
dotnet add package Microsoft.ApplicationInsights.AspNetCore
dotnet add package Microsoft.ApplicationInsights.WorkerService
I updated appsettings.json:
{
"ApplicationInsights": {
"ConnectionString": "InstrumentationKey=<Your_Instrumentation_Key>;IngestionEndpoint=https://<Your_Region>.applicationinsights.azure.com/"
}
}
For program.cs
I've added these lines
I've also added this package
dotnet add package Serilog.Sinks.ApplicationInsights
and added this also in program.cs
I do not see any logging going into my app insights instance in the azure portal; however, when I log onto the windows service machine and look at logs, I'm getting logs:
What am I doing wrong? How do I get app insights working on a windows service alongside serilog?
If it is not possible to use serilog and app insights together, I'd love to just throw serilog out and only keep app insights.
Upvotes: 0
Views: 135
Reputation: 11383
I have used below code in my Program.cs and it worked :
var rithapp = "Application";
var rith_constr = "InstrumentationKey=b7a45ed9=fb6;IngestionEndpoint=https://canadacentral-1.in.applicationinsights.azure.com/;LiveEndpoint=https://canadacentral.livediagnostics.monitor.azure.com/;ApplicationId=5aa2ed1aa";
Log.Logger = new LoggerConfiguration()
.Enrich.FromLogContext()
.Enrich.WithProperty("ApplicationName", rithapp)
.WriteTo.ApplicationInsights(rith_constr, new TraceTelemetryConverter())
.CreateLogger();
Log.Information("Hello Rithwik, Windows Running");
Packages:
System.ServiceProcess
Serilog
Serilog.Sinks.ApplicationInsights.TelemetryConverters
Output:
Upvotes: 1