title: Application Insights Trace Listener for ASP.NET Core 2.0
body: <p>I have a bunch of services which emit <code>System.Diagnostics.Trace.*</code> trace messages.  When hosted via ASP.NET WebAPI, I simply include the <code>Microsoft.ApplicationInsights.TraceListener</code> package and my custom traces from the service libs are collected in app insights.</p>
  
  <p>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...</p>
  
  <h3>Add Application Insights</h3>
  
  <pre><code>public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
      {
          loggerFactory.AddApplicationInsights(app.ApplicationServices, Microsoft.Extensions.Logging.LogLevel.Information);
       //...
      }
  </code></pre>
  
  <p>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.</p>
  
  <h3>Add Trace Listener Package</h3>
  
  <p>I decided to add in the <code>Microsoft.ApplicationInsights.TraceListener</code> package just to see if that would help.  I updated the configure method to look like this...</p>
  
  <pre><code>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);
      }
  </code></pre>
  
  <p>After updating the configuration, I now see the trace messages duplicated in the logs, but none of the custom traces are present still.</p>
  
  <p>Here is the <a href="https://github.com/Microsoft/ApplicationInsights-aspnetcore/issues/589#issuecomment-372754260" rel="noreferrer">issue on github</a>.  Here is a <a href="https://github.com/spelltwister/AspNetCoreAppInsightsTrace" rel="noreferrer">sample repo</a> with the issue.</p>