Skip to content
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
@cesarblum

Description

@cesarblum

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.

Activity

added this to the 1.0.0 milestone on May 9, 2016
muratg

muratg commented on May 9, 2016

@muratg

I think this is a dup of #335

@CesarBS is this implementation specific or does it repro regardless of the provider?

cesarblum

cesarblum commented on May 10, 2016

@cesarblum
ContributorAuthor

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

modified the milestones: 1.0.1, 1.0.0 on May 19, 2016
changed the title [-]Passing null for message or message args makes logger throws[/-] [+]Passing null for message or message args makes logger throw[/+] on Jun 10, 2016
changed the title [-]Passing null for message or message args makes logger throw[/-] [+]Loggers throw on null message or arguments[/+] on Jun 10, 2016
cesarblum

cesarblum commented on Jun 10, 2016

@cesarblum
ContributorAuthor

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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @cesarblum@muratg@danroth27@natemcmaster

      Issue actions

        Loggers throw on null message or arguments · Issue #422 · aspnet/Logging