Reputation:
Currently I am using Log4net Appender for App Insight, to log the error to Application Insight.
TelemetryConfiguration.Active.InstrumentationKey = "XXXX";
var tc = new TelemetryClient();
var log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
XmlConfigurator.Configure();
log.Error(ex+ "@"+ CodeBlock); **IN this case its loggin as Trace.** log.Fatal(ex + "@" + CodeBlock);
log.Info(ex + "@" + CodeBlock);
TelemetryConfiguration.Active.TelemetryChannel.DeveloperMode = true;
tc.Flush();
Thread.Sleep(5000);
In this case, all of the events are logged as Trace. But where I expect it logged as exception. I can use telemetry object to pass the exception but then there won't be any result of using of Log4net. We can't pass the log entry to any other logging tools except App insight.
Upvotes: 0
Views: 493
Reputation: 29940
For logged as exception, you should use this line of code log.Error("your message",new Exception());
In visual studio output window, if you use log.Error("your message",new Exception());
, you can see the Application Insights Telemetry
has a name ends with Exception
, like below:
Then go to azure portal, you can see the it goes as Exception, screenshot below:
Upvotes: 1