Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

LogInformation(string) throws FormatException #351

Closed
Tratcher opened this issue Jan 28, 2016 · 1 comment
Closed

LogInformation(string) throws FormatException #351

Tratcher opened this issue Jan 28, 2016 · 1 comment
Assignees
Milestone

Comments

@Tratcher
Copy link
Member

https://github.com/aspnet/Hosting/blob/dev/src/Microsoft.AspNetCore.Server.Testing/Deployers/SelfHostDeployer.cs#L81
Logger.LogInformation(dataArgs.Data ?? string.Empty);

System.AggregateException: An error occurred while writing to logger(s). (Index (zero based) must be greater than or equal to zero and less than the size of the argument list.) ---> System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
   at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.Format(IFormatProvider provider, String format, Object[] args)
   at Microsoft.Extensions.Logging.Internal.LogValuesFormatter.Format(Object[] values)
   at Microsoft.Extensions.Logging.Internal.FormattedLogValues.ToString()
   at Microsoft.Extensions.Logging.LoggerExtensions.MessageFormatter(Object state, Exception error)
   at Microsoft.Extensions.Logging.Console.ConsoleLogger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
   at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
   --- End of inner exception stack trace ---
   at Microsoft.Extensions.Logging.Logger.Log[TState](LogLevel logLevel, EventId eventId, TState state, Exception exception, Func`3 formatter)
   at Microsoft.Extensions.Logging.LoggerExtensions.LogInformation(ILogger logger, String message, Object[] args)
   at Microsoft.AspNetCore.Server.Testing.SelfHostDeployer.<StartSelfHost>b__3_1(Object sender, DataReceivedEventArgs dataArgs)
   at System.Diagnostics.Process.OutputReadNotifyUser(String data)

If the data contains curly brackets then logging may throw a format exception. The logger should not attempt to format data for a simple string with no parameters.

logger.Log(LogLevel.Information, 0, new FormattedLogValues(message, args), null, _messageFormatter);

This failed some tests in MusicStore

@BrennanConroy
Copy link
Member

Fixed via 6e8bcd9

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

2 participants