ConsoleApplication.cs 716 B

123456789101112131415161718192021222324
  1. using Microsoft.Extensions.Logging.Console;
  2. namespace PCC.Common.Init;
  3. public static class ConsoleApplication
  4. {
  5. public static void Init()
  6. {
  7. GenericPurposeApplication.Init();
  8. }
  9. public static void SetLogFormatForSimpleConsole(this IHostApplicationBuilder builder, bool singleLine = true, string timestampFormat = "[dd HH:mm:ss] ", LoggerColorBehavior colorBehavior = LoggerColorBehavior.Enabled)
  10. {
  11. builder.Services.AddLogging(opt =>
  12. {
  13. opt.AddSimpleConsole(p =>
  14. {
  15. p.TimestampFormat = timestampFormat;
  16. p.SingleLine = singleLine;
  17. p.ColorBehavior = colorBehavior;
  18. });
  19. });
  20. }
  21. }