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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions