Application Insights doesn't sent log4net log message with appended exception object to Azure

application insights not working
application insights telemetry (unconfigured)
application insights on-premise
application insights logging
application insights c#
application insights without azure
application insights webapi
@microsoft/applicationinsights-web

Our current project consists of an ASP.NET application as well as a few smaller console applications. We are using Microsofts Application Insights for the application management of the ASP.NET app. Now we want to integrate Application Insights in the console applications as well to be able to centralize our logging to Azure. Our legacy logging is implemented with Log4Net. After configuring Application Insights Core and its corresponding Log4Net Appender in the console application we are able to see our log entries in Azure as expected. Every log message coming from the console application is sent to Azure, except for the logs which are getting an additional object appended from us. For example our log messages with severity level Error which contains the exception objects as second parameter:

Log.Error("This looks like an error", ex);

These log entries aren't displayed at all in Azure. They are only displayed when putting the exception object into the message like:

Log.Error($"This looks like an error. Exception: {ex}");

So it seems like there is a size limit regarding the exception objects from Log4Net but not the actual message? If so is this in any way configurable? Because changing every 'Log.Error();' in the whole project is not an option.

Our ApplicationInsights.config file:

<?xml version="1.0" encoding="utf-8"?>
<ApplicationInsights xmlns="http://schemas.microsoft.com/ApplicationInsights/2013/Settings">
   <InstrumentationKey>[Our key]</InstrumentationKey>
   <TelemetryChannel Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.ServerTelemetryChannel, Microsoft.AI.ServerTelemetryChannel"/>

   <TelemetryProcessors>
      <Add Type="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel.AdaptiveSamplingTelemetryProcessor, Microsoft.AI.ServerTelemetryChannel">
         <MaxTelemetryItemsPerSecond>5</MaxTelemetryItemsPerSecond>
         <ExcludedTypes>Trace;Exception</ExcludedTypes>
      </Add>
   </TelemetryProcessors>
</ApplicationInsights>

Edit:

Log4Net configuration:

<!-- ... -->
<!-- Configuration of logfile and console appender -->
<!-- ... -->

<root>
  <level value="ALL" />
  <appender-ref ref="logfile" />
  <appender-ref ref="console" />
  <appender-ref ref="aiAppender" />
</root>

<appender name="aiAppender" type="Microsoft.ApplicationInsights.Log4NetAppender.ApplicationInsightsAppender, Microsoft.ApplicationInsights.Log4NetAppender">
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%message%newline" />
  </layout>
</appender>

There is no issue with the other appenders.

I figured it out. What caused the problem was that as soon as you append an exception object to any of the logging methods of Log4Net:

Log.Error(message, exception);
Log.Warn(message, exception);
Log.Info(message, exception);

The specifc log entry isn't handled as trace but as exception in Application Insights. So adjusting the filter in the Application Insights tab in Azure to also show exceptions was enough. Now I'm able to see the Log.Error(message, exception) entries in Azure as well.

I don't know why this is handled like this, because this makes processing the logs more complex for third party software (For example: Exceptions doesn't have an explicit message field in Application Insights, etc.).

What is Azure Application Insights?, I have everything reported to Application Insights except request once we deploy to If @alainvezina doesn't mind, this issue can be closed. What does Application Insights monitor? Application Insights is aimed at the development team, to help you understand how your app is performing and how it's being used. It monitors: Request rates, response times, and failure rates - Find out which pages are most popular, at what times of day, and where your users are. See which pages perform best.

As long as you are passing an exception it will be logged as an exception whatever the type of logging method you are using .. if you want it to be logged as trace you shouldn't pass an exception. Which makes sense

Application Insights report no request · Issue #766 · microsoft , I just found the answer for this in a solved issue on the Application Insights Github​. The solution is to open your ApplicationInsights.config and  The Application Insights SDK for ASP.NET Corecan monitor your applications no matter where or how they run. If your application is running and has network connectivity to Azure, telemetry can be collected. Application Insights monitoring is supported everywhere .NET Core is supported.

Application Insights does not log successful requests, For programming questions about Microsoft's Azure Application Insights, Cannot display AppInsights of AppService in Azure - Cannot read property 'id' of null. As far as I know the Application Insights services are only available from the Central US location. Which can be causing the error, because you are trying to set up an Insights component in the East US region. As you can see, the location is locked and therefore it is not possible to choose for East US.

Newest 'azure-application-insights' Questions, Visual Studio Application Insights is an extensible analytics service that monitors Unlike the setup for other Application Insights SDKs, adding the SDK doesn't  I wrote a custom logger for Application Insights in my app. I don't see any exceptions or ANY events when viewing App Insights in Azure Portal. Here is the logger class code, when I debug the code I do see a key assigned to the InstrumentationKey property, any ideas what I am doing wrong here?

Monitoring Applications using Application Insights, The Application Insights REST API lets you query the performance and usage By contrast, the Application Id doesn't change, and you can go back and get it at  Application Insights is designed to get everything you need to monitor the availability, performance, and usage of your web applications, whether they're hosted on Azure or on-premises.

Getting the Most Out of Application Insights for .NET (Core) Apps , App Insights does pick up the 2 logging messages via log4net, but doesn't show anything for dependency calls. Calls to Remote Dependencies. It  There's no Application Insights option on the project context menu Make sure that Developer Analytics Tools is installed on the development machine. At Visual Studio Tools > Extensions This might be a project type that Developer Analytics Tools doesn't support. Use manual installation.

Comments
  • btw. Serilog does the same stuff - events containing Exceptions are sent as exception and not as a trace - it is documented here: github.com/serilog/serilog-sinks-applicationinsights I am not sure if this is good behavior, the message of the log event gets lost and only Exception is sent to App Insights
  • did you find a solution for this to send the logs as trace instead as exception? I have the same problem as you. The exceptions are logged in Application Insights but the message part gets lost.
  • Unfortunately not.
  • I solved this problem by sending 2 events to App Insights - Message with Exception will be sent separated. Message as Trace and Exception as Exception. In App Insights you can join Traces with Exceptions by Operation_ID and get wanted result.
  • Installed is the latest stable version (which is currently 2.2.0) of the Log4NetAppender. As well as the latest stable version (2.4.0) for ApplicationInsights Core.