From c09e268e4deccdd2c6eee62520e433c90b9d1f42 Mon Sep 17 00:00:00 2001 From: Maksym Sadovnychyy Date: Sun, 25 May 2025 21:01:24 +0200 Subject: [PATCH] (feature): logger builder console extensions --- .../Logging/LoggingBuilderExtensions.cs | 19 ++++++++++++++++++- src/MaksIT.Core/MaksIT.Core.csproj | 16 +++++++++------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/MaksIT.Core/Logging/LoggingBuilderExtensions.cs b/src/MaksIT.Core/Logging/LoggingBuilderExtensions.cs index 64b2742..4dd97da 100644 --- a/src/MaksIT.Core/Logging/LoggingBuilderExtensions.cs +++ b/src/MaksIT.Core/Logging/LoggingBuilderExtensions.cs @@ -1,6 +1,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; - +using Microsoft.Extensions.Hosting; namespace MaksIT.Core.Logging; @@ -9,4 +9,21 @@ public static class LoggingBuilderExtensions { builder.Services.AddSingleton(new FileLoggerProvider(filePath)); return builder; } + public static ILoggingBuilder AddConsole(this ILoggingBuilder logging, IHostEnvironment env) { + logging.ClearProviders(); + if (env.IsDevelopment()) { + logging.AddSimpleConsole(options => { + options.IncludeScopes = true; + options.SingleLine = false; + options.TimestampFormat = "hh:mm:ss "; + }); + } + else { + logging.AddJsonConsole(options => { + options.IncludeScopes = true; + options.TimestampFormat = "yyyy-MM-ddTHH:mm:ss.fffZ"; + }); + } + return logging; + } } diff --git a/src/MaksIT.Core/MaksIT.Core.csproj b/src/MaksIT.Core/MaksIT.Core.csproj index 9f3345b..bdce300 100644 --- a/src/MaksIT.Core/MaksIT.Core.csproj +++ b/src/MaksIT.Core/MaksIT.Core.csproj @@ -8,7 +8,7 @@ MaksIT.Core - 1.3.8 + 1.3.9 Maksym Sadovnychyy MAKS-IT MaksIT.Core @@ -25,11 +25,13 @@ - - - - - - + + + + + + + +