Skip to content
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
cesarblum opened this issue May 9, 2016 · 3 comments
Closed

Loggers throw on null message or arguments #422

cesarblum opened this issue May 9, 2016 · 3 comments
Assignees

Comments

@cesarblum
Copy link
Contributor

cesarblum commented May 9, 2016

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.

@danroth27 danroth27 added this to the 1.0.0 milestone May 9, 2016
@danroth27 danroth27 added the bug label May 9, 2016
@muratg
Copy link

muratg commented 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
Copy link
Contributor Author

@muratg Seems to repro regardless of provider. Notice there's no particular provider in the stack trace.

@muratg muratg added up-for-grabs We will consider contributions 1 - Ready labels May 19, 2016
@muratg muratg modified the milestones: 1.0.1, 1.0.0 May 19, 2016
@cesarblum cesarblum changed the title Passing null for message or message args makes logger throws Passing null for message or message args makes logger throw Jun 10, 2016
@cesarblum cesarblum changed the title Passing null for message or message args makes logger throw Loggers throw on null message or arguments Jun 10, 2016
@cesarblum
Copy link
Contributor Author

Current agreement is that logging abstractions should not swallow logger exceptions.

We should still harden our loggers (Console, Debug, etc.) against nulls.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants