Closed MichaCo closed 7 years ago
I dont know if this one has creeped back or not, but i am getting in one of my environments with asp.net core 2.2 (SDK 2.2.100, target netcoreapp2.2, Microsoft.ApplicationInsights.AspNetCore 2.6.1). Running in Azure App Service using the run from zip package option.
Runs perfectly outside of zip package.
System.AggregateException: An error occurred while writing to logger(s). (Object reference not set to an instance of an object.) ---> System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.ApplicationInsights.AspNetCore.Logging.ApplicationInsightsLogger.<>c__DisplayClass9_0
1.1.ForEach(Action
1 action)
at Microsoft.ApplicationInsights.AspNetCore.Logging.ApplicationInsightsLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func3 formatter) at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func
3 formatter)
--- End of inner exception stack trace ---
at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func3 formatter) at Microsoft.Extensions.Logging.Logger
1.Microsoft.Extensions.Logging.ILogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
at Microsoft.Extensions.Logging.LoggerMessage.<>cDisplayClass4_0.1.<Log>b__0(DictionaryEntry item) at System.Collections.Generic.List
1.ForEach(Action1 action) at Microsoft.ApplicationInsights.AspNetCore.Logging.ApplicationInsightsLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func
3 formatter)
at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func3 formatter)<---
I am using below:
Microsoft.ApplicationInsights.AspNetCore - 2.6.1
.Net core - 2.2
Still getting below error sometimes:
(Inner Exception #0) System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.ApplicationInsights.AspNetCore.Logging.ApplicationInsightsLogger.<>c__DisplayClass9_0`1.<Log>b__0(DictionaryEntry item)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at Microsoft.ApplicationInsights.AspNetCore.Logging.ApplicationInsightsLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)<---
I thought it was fixed in version 2.4 as mentioned in https://social.msdn.microsoft.com/Forums/aspnet/en-US/e8ca1a8c-d5f2-4c90-945e-3325c0aa771a/random-loginfo-exceptions?forum=AzureFunctions
Agreeing with @melborp
The exception happens when using AI together with Microsoft.Extensions.Logging.
I did not set up AI correctly by not having the
UseApplicationInsights
on the webhost builderand later on in my Startup.cs I configure to have AI on the logger factory, too:
Now, if you try to log any message with
_logger.LogWarning(...)
for example, you'll get aNullReferenceException
.Why would I not configure the WebHostBuilder correctly you may ask, well, I encountered that while trying to get the Microsoft.AspNetCore.TestHost.TestServer running for unit testing my web app. While doing unit tests, I do not want to trigger AI events.
Also, In general, NullReferenceException is a little bit rude ;)
Expected behavior The expected behavior would be, that it just doesn't do anything. Logging should never throw any unexpected exceptions at runtime