0

I have two console applications A and B. These two projects are hosted as Azure Webjobs. I configured console, rolling file and app. Insights appenders in a common project C, ConfigManager.cs file.

A is calling C.ConfigManager to configure appenders. A.Orchestrator able to log messages to all 3 appenders.

B is also calling C.ConfigManager to configure appenders. B.Orchestrator is able to log messages to console and rolling file appender but not to Application Insights.

All my log4net configurations are pretty much static. I am unable to find what could be the root cause here

Pradeep
  • 29
  • 4
  • You should not be using rolling file appender, I think. https://stackoverflow.com/questions/28800320/log4net-with-application-insights – Chetan Mar 27 '19 at 02:18
  • https://learn.microsoft.com/en-us/azure/azure-monitor/app/asp-net-trace-logs – Chetan Mar 27 '19 at 02:19
  • I don't see problem with rolling file appender. Please read the issue again. I am not seeing any logs in AI but can view in file and console. – Pradeep Mar 27 '19 at 03:19
  • 1
    TelemetryConfiguration.Active.TelemetryChannel.Flush() is flushing logs to application insights. I am still checking why these logs are not flushed automatically – Pradeep Mar 27 '19 at 18:11
  • Hi @Pradeep, did you found any solution for this issue? Because I am also facing the same issue. – aryan Dec 23 '20 at 12:33

2 Answers2

0

You can try using internal debug of log4net:

Something like this:

<appSettings>
    <add key="log4net.Internal.Debug" value="true"/>
</appSettings>

then write to a file:

<system.diagnostics>
    <trace autoflush="true">
        <listeners>
            <add 
                name="textWriterTraceListener" 
                type="System.Diagnostics.TextWriterTraceListener" 
                initializeData="C:\users\desktop\log.txt" />
        </listeners>
    </trace>
</system.diagnostics>

Alternative, you can check the version of ApplicationInsights. If its older than AILog4netAppender, then try to upgrade the version.

Gauravsa
  • 6,330
  • 2
  • 21
  • 30
0

The telemetry data is not sent to application insights immediately, it will batched then send.

So for console app, you'd better add some sleep time like System.Threading.Thread.Sleep(1000) before console app exits.

Hope it helps.

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
  • It is correct that telemetry data is not uploaded to azure as soon application logs these events. In my case, console application runs for more than 5 minutes and yet logs are not uploaded. – Pradeep Mar 28 '19 at 12:21