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.