Log4Net with Application Insights

后端 未结 4 1642
Happy的楠姐
Happy的楠姐 2020-12-29 03:59

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 wo

4条回答
  •  被撕碎了的回忆
    2020-12-29 04:53

    I also had some problems with sending my Log4Net logs to AI in a Sitecore website. Sitecore has their own implementation of Log4Net so it didn't worked with the AI Nuget package. I've made my own Apprender in which I send the logs to AI.

     public class CustomLogFileAppender : SitecoreLogFileAppender
        {
            protected override void Append(LoggingEvent loggingEvent)
            {
                if (Sitecore.Context.Site != null )
                {
    
                    if(loggingEvent.Level == Level.FATAL)
                    {
                        AppsInsightsLogHelper.Critical(loggingEvent.RenderedMessage);
                    }
    
                    if (loggingEvent.Level == Level.ERROR)
                    {
                        AppsInsightsLogHelper.Error(loggingEvent.RenderedMessage);
                    }
    
                    if (loggingEvent.Level == Level.WARN)
                    {
                        AppsInsightsLogHelper.Warning(loggingEvent.RenderedMessage);
                    }
    
                    if(loggingEvent.Level == Level.INFO)
                    {
                        AppsInsightsLogHelper.Info(loggingEvent.RenderedMessage);
                    }
    
    
                }
    
                    base.Append(loggingEvent);
            }
        }
    

    In sitecore.config:

    
        
          ...
        
    
    

提交回复
热议问题