This repository was archived by the owner on Dec 13, 2018. It is now read-only.
This repository was archived by the owner on Dec 13, 2018. It is now read-only.
Loggers throw on null message or arguments #422
Closed
Description
Part of https://github.com/aspnet/Release/issues/31
Log*(null)
or Log*("{0}", null)
makes the logger throw:
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Extensions.Logging.Internal.FormattedLogValues..ctor(String format, Object[] values)
at Microsoft.Extensions.Logging.LoggerExtensions.LogTrace(ILogger logger, String message, Object[] args)
at WebApplicationLoggingNetFramework.Startup.Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) in C:\Users\cesars\Documents\Visual Studio 2015\Projects\WebApplicationLoggingNetFramework\src\WebApplicationLoggingNetFramework\Startup.cs:line 32
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.Startup.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
Logging should be more resilient to this. Print (null)
or something similar when a null is logged.
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
muratg commentedon May 9, 2016
I think this is a dup of #335
@CesarBS is this implementation specific or does it repro regardless of the provider?
cesarblum commentedon May 10, 2016
@muratg Seems to repro regardless of provider. Notice there's no particular provider in the stack trace.
[-]Passing null for message or message args makes logger throws[/-][+]Passing null for message or message args makes logger throw[/+][-]Passing null for message or message args makes logger throw[/-][+]Loggers throw on null message or arguments[/+]cesarblum commentedon Jun 10, 2016
Current agreement is that logging abstractions should not swallow logger exceptions.
We should still harden our loggers (Console, Debug, etc.) against
null
s.