Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4Net with Application Insights

I am trying to configure my azure asp.net website to send log4net traces to Azure Application Insights. I can see in my azure console page views etc, hence I know that is working fine. I can also see log4net traces, when configured with a file handler, but when configuring log4net to use the application insights handler I don't see any log4net entries appear in the application insight dashboard, no errors or warnings at build or run time - just no results in the dashboard. I have looked at the network traffic in Fiddler, and I can see the pageview data etc being sent to application insights, but not the log4net trace traffic hence I suspect this is a configuration issue.

Separately I have tried the TelemetryClient() in my main project, and I see the tracetraffic sucesfully in the dashboard. However, this does not fit my use case as TelemetryClient does not seem to support non asp.net dll's as yet (i.e. my business and data logic which are in separate dll's).

Anyone offer any insight or advice?

I have installed the nuget package for Microsoft.ApplicationInsights.Log4NetAppender.dll and I am using Microsoft.ApplicationInsights.0.13.2-build00132

I have the following in my web.config as per https://blog.ehn.nu/2014/11/using-log4net-for-application-insights/

<configuration>   <configSections>     <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>   </configSections>   <log4net>     <root>       <level value="ALL"/>       <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>   </log4net> <configuration> 
like image 825
BMac Avatar asked Mar 01 '15 23:03

BMac


People also ask

What is traces in application insights?

Trace telemetry (in Application Insights) represents printf style trace statements that are text-searched. Log4Net , NLog , and other text-based log file entries are translated into instances of this type. The trace does not have measurements as an extensibility.

Where is stack trace in application insights?

Open the Application Insights Search telemetry window in Visual Studio. While debugging, select the Application Insights dropdown box. Select an exception report to show its stack trace.

How do I get logs from application insights?

View logs in Application InsightsGo to Application Insights resource in your resource group. Go to Logs under Monitoring section. Click on traces eye button to get log traces. Select Time Range and click Run.


1 Answers

Try installing the PreRelease version of the Log4Net Appender.

I had created a canonical ASP.NET MVC example following the steps created by someone else and had the same problem above. But then followed some steps written in the Application Insights documentation and discovered that those specified installing the PreRelease package for the log4net appender. Having done that it workd :)

like image 55
Phil Avatar answered Sep 29 '22 06:09

Phil