I have a .NET 4.5 project that produces a class library that services a web API. When I attempt to start the project, I get the following message:
<<<<<
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during
the execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Source File: ...\Global.asax.cs Line: 41
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.ApplicationInsights.NLogTarget.ApplicationInsightsTarget.Write(LogEventInfo logEvent) +76
NLog.Targets.Target.Write(AsyncLogEventInfo logEvent) +46
[NLogRuntimeException: Exception occurred in NLog]
NLog.<>c__DisplayClass1.<Write>b__0(Exception ex) +79
NLog.Internal.SingleCallContinuation.Function(Exception exception) +89
NLog.Targets.Target.Write(AsyncLogEventInfo logEvent) +92
NLog.Targets.Target.WriteAsyncLogEvent(AsyncLogEventInfo logEvent) +217
NLog.LoggerImpl.WriteToTargetWithFilterChain(TargetWithFilterChain targetListHead, LogEventInfo logEvent, AsyncContinuation onException) +168
NLog.LoggerImpl.Write(Type loggerType, TargetWithFilterChain targets, LogEventInfo logEvent, LogFactory factory) +181
NLog.Logger.WriteToTargets(LogLevel level, IFormatProvider formatProvider, String message, Object[] args) +89
NLog.Logger.Log(LogLevel level, String message, String argument) +71
O2.Queue.Api.JmsTopic.StartListening(String affinity) +67
O2.Queue.Api.JmsTopic.StartListening() +7
O2.Transmog.Service.WebApiApplication.Application_Start() in d:\Dev\Email-Transmogrifier\O2.Transmog\O2.Transmog.Service\Global.asax.cs:41
[HttpException (0x80004005): Exception occurred in NLog]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +9935033
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +118
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +172
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +336
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +296
[HttpException (0x80004005): Exception occurred in NLog]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +9913572
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +101
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +254
|
>>>>>
The error occurs processing the project's Global.asax file, in the Application_Start event handler. One of the lines is causing an exception to be raised, and NLog is presumably attempting to log the exception.
Here is my NLog.config file:
<<<<<
<?xml version="1.0" encoding="utf-8"?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwExceptions="true"
internalLogLevel="Debug"
internalLogToConsole="false">
<extensions>
<add assembly="Microsoft.ApplicationInsights.NLogTarget" />
</extensions>
<targets>
<!-- target xsi:type="Null" name="NullTarget" formatMessage="Boolean" layout="Layout" / -->
<target xsi:type="ApplicationInsightsTarget" name="aiTarget" componentId="c998bcfe-9b8d-41c0-a4cb-4e49ba93bcc3"/>
</targets>
<rules>
<!-- logger name="NullLogger" minlevel="Trace" writeTo="NullTarget"/-->
<logger name="*" minlevel="Trace" writeTo="aiTarget"/>
</rules>
</nlog>>>>>>
Note that the target named "NullTarget" is remarked out. If I un-remark the target (without un-remarking its corresponding rule, named "NullLogger"), my error goes away.
Can anybody explain this behavior? Thanks in advance!