Does AnsiConsole support message templates? #1198
-
Hi, Does AnsiConsole support message templates, as described over https://learn.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-7.0#lmt ? Looking at the 'AnsiConsole.WriteLine(string format, params object[] args)' I thought it does, but I am getting an 'System.FormatException: 'Input string was not in a correct format.' exception so I guess it doesn't? Below you can find a code example that tries to clarify my question. Please create a C# console application, add the two nuget packages "Microsoft.Extensions.Logging.Console" and "Spectre.Console" and try out this sample: Thank you in advance using Spectre.Console;
using Microsoft.Extensions.Logging;
namespace SpectreConsole_MessageTemplateTest
{
/// <summary>
/// Quick and dirty try out of possible AnsiConsole.WriteLine message templates support.
/// </summary>
internal class Program
{
private static ILogger<Program> _logger;
static void Main(string[] args)
{
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddFilter("Microsoft", LogLevel.Warning)
.AddFilter("System", LogLevel.Warning)
.AddFilter("SampleApp.Program", LogLevel.Debug)
.AddConsole();
});
_logger = loggerFactory.CreateLogger<Program>();
WriteMessage("It is {todayTime}. Exacty 24 hours ago it was {yesterdayTime}.", DateTime.Now.ToString(), DateTime.Now.AddDays(-1).ToString());
}
static void WriteMessage(string message, params object[] args)
{
_logger.LogWarning(message, args);
AnsiConsole.WriteLine(message, args); // Gets an 'System.FormatException: 'Input string was not in a correct format.'
}
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
@pedroduarte0 No, |
Beta Was this translation helpful? Give feedback.
@pedroduarte0 No,
AnsiConsole.WriteLine
is analog toConsole.WriteLine
.