I have a bunch of services which emit System.Diagnostics.Trace.*
trace messages. When hosted via ASP.NET WebAPI, I simply include the Microsoft.ApplicationInsights.TraceListener
package and my custom traces from the service libs are collected in app insights.
However, I cannot figure out how to get these same messages when hosting the services via ASP.NET Core 2.0 WebAPI. What I've tried...
Add Application Insights
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddApplicationInsights(app.ApplicationServices, Microsoft.Extensions.Logging.LogLevel.Information);
//...
}
After adding application insights using the extension method, I am able to see the traces emitted by the framework (eg, Request Start, Request End, ...), but none of my custom trace messages are present.
Add Trace Listener Package
I decided to add in the Microsoft.ApplicationInsights.TraceListener
package just to see if that would help. I updated the configure method to look like this...
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddTraceSource(new System.Diagnostics.SourceSwitch("AppInsightsTraceSwitch")
{
Level = System.Diagnostics.SourceLevels.All
}, new Microsoft.ApplicationInsights.TraceListener.ApplicationInsightsTraceListener());
loggerFactory.AddApplicationInsights(app.ApplicationServices, Microsoft.Extensions.Logging.LogLevel.Information);
}
After updating the configuration, I now see the trace messages duplicated in the logs, but none of the custom traces are present still.
Here is the issue on github. Here is a sample repo with the issue.