From bcfec78d1013fc86e8f1d3b9c4a6b83d8aaeba4b Mon Sep 17 00:00:00 2001 From: Dion Date: Sun, 10 Mar 2024 20:37:28 +0100 Subject: [PATCH 1/5] Less verbose in console mode --- .../starsky.foundation.platform/Services/WebLogger.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/starsky/starsky.foundation.platform/Services/WebLogger.cs b/starsky/starsky.foundation.platform/Services/WebLogger.cs index 66b2065901..1a541483b1 100644 --- a/starsky/starsky.foundation.platform/Services/WebLogger.cs +++ b/starsky/starsky.foundation.platform/Services/WebLogger.cs @@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging; using starsky.foundation.injection; using starsky.foundation.platform.Interfaces; +using starsky.foundation.platform.Models; namespace starsky.foundation.platform.Services { @@ -14,6 +15,7 @@ public sealed class WebLogger : IWebLogger { private readonly ILogger? _logger; private readonly IConsole? _console; + private readonly AppSettings? _appSettings; /// /// Trace = 0, Debug = 1, Information = 2, Warning = 3, Error = 4, Critical = 5, and None = 6. @@ -25,7 +27,9 @@ public WebLogger(ILoggerFactory? loggerFactory = null, IServiceScopeFactory? sco { _logger = loggerFactory?.CreateLogger("app"); var scopeProvider = scopeFactory?.CreateScope().ServiceProvider; - if ( scopeProvider != null ) _console = scopeProvider.GetService(); + if ( scopeProvider == null ) return; + _console = scopeProvider.GetService(); + _appSettings = scopeProvider.GetService(); } public void LogDebug(string? message, params object[] args) @@ -35,12 +39,13 @@ public void LogDebug(string? message, params object[] args) return; } - if ( _logger == null ) + if ( _logger == null && _appSettings?.Verbose == true ) { _console?.WriteLine(message); return; } - _logger.LogDebug(message, args); + + _logger?.LogDebug(message, args); } public void LogInformation(string? message, params object[] args) From 8219d485ef31f7be8929830fb48c5176a6a2b0bb Mon Sep 17 00:00:00 2001 From: Dion Date: Thu, 14 Mar 2024 22:16:34 +0100 Subject: [PATCH 2/5] undo change && add WebLogger to missing projects --- starsky/starsky.foundation.platform/Services/WebLogger.cs | 6 ++---- starsky/starskywebftpcli/Program.cs | 5 +++++ starsky/starskywebftpcli/starskywebftpcli.csproj | 1 + starsky/starskywebhtmlcli/Program.cs | 7 ++++++- starsky/starskywebhtmlcli/starskywebhtmlcli.csproj | 1 + 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/starsky/starsky.foundation.platform/Services/WebLogger.cs b/starsky/starsky.foundation.platform/Services/WebLogger.cs index 1a541483b1..dd663d51ae 100644 --- a/starsky/starsky.foundation.platform/Services/WebLogger.cs +++ b/starsky/starsky.foundation.platform/Services/WebLogger.cs @@ -15,7 +15,6 @@ public sealed class WebLogger : IWebLogger { private readonly ILogger? _logger; private readonly IConsole? _console; - private readonly AppSettings? _appSettings; /// /// Trace = 0, Debug = 1, Information = 2, Warning = 3, Error = 4, Critical = 5, and None = 6. @@ -29,7 +28,6 @@ public WebLogger(ILoggerFactory? loggerFactory = null, IServiceScopeFactory? sco var scopeProvider = scopeFactory?.CreateScope().ServiceProvider; if ( scopeProvider == null ) return; _console = scopeProvider.GetService(); - _appSettings = scopeProvider.GetService(); } public void LogDebug(string? message, params object[] args) @@ -39,13 +37,13 @@ public void LogDebug(string? message, params object[] args) return; } - if ( _logger == null && _appSettings?.Verbose == true ) + if ( _logger == null ) { _console?.WriteLine(message); return; } - _logger?.LogDebug(message, args); + _logger.LogDebug(message, args); } public void LogInformation(string? message, params object[] args) diff --git a/starsky/starskywebftpcli/Program.cs b/starsky/starskywebftpcli/Program.cs index e9af36f70a..a9481cd568 100644 --- a/starsky/starskywebftpcli/Program.cs +++ b/starsky/starskywebftpcli/Program.cs @@ -7,6 +7,8 @@ using starsky.foundation.platform.Interfaces; using starsky.foundation.platform.Models; using starsky.foundation.storage.Interfaces; +using starsky.foundation.webtelemetry.Extensions; +using starsky.foundation.webtelemetry.Helpers; namespace starskywebftpcli { @@ -25,6 +27,9 @@ public static async Task Main(string[] args) var serviceProvider = services.BuildServiceProvider(); var appSettings = serviceProvider.GetRequiredService(); + services.AddOpenTelemetryMonitoring(appSettings); + services.AddTelemetryLogging(appSettings); + serviceProvider = services.BuildServiceProvider(); var storageSelector = serviceProvider.GetRequiredService(); diff --git a/starsky/starskywebftpcli/starskywebftpcli.csproj b/starsky/starskywebftpcli/starskywebftpcli.csproj index 0a8977c4f2..3e78b8966a 100644 --- a/starsky/starskywebftpcli/starskywebftpcli.csproj +++ b/starsky/starskywebftpcli/starskywebftpcli.csproj @@ -14,6 +14,7 @@ + diff --git a/starsky/starskywebhtmlcli/Program.cs b/starsky/starskywebhtmlcli/Program.cs index 3feeb5e097..fe1e518bb7 100644 --- a/starsky/starskywebhtmlcli/Program.cs +++ b/starsky/starskywebhtmlcli/Program.cs @@ -8,6 +8,8 @@ using starsky.foundation.platform.Interfaces; using starsky.foundation.platform.Models; using starsky.foundation.storage.Interfaces; +using starsky.foundation.webtelemetry.Extensions; +using starsky.foundation.webtelemetry.Helpers; namespace starskywebhtmlcli { @@ -24,7 +26,10 @@ public static async Task Main(string[] args) RegisterDependencies.Configure(services); var serviceProvider = services.BuildServiceProvider(); var appSettings = serviceProvider.GetRequiredService(); - + + services.AddOpenTelemetryMonitoring(appSettings); + services.AddTelemetryLogging(appSettings); + new SetupDatabaseTypes(appSettings, services).BuilderDb(); serviceProvider = services.BuildServiceProvider(); diff --git a/starsky/starskywebhtmlcli/starskywebhtmlcli.csproj b/starsky/starskywebhtmlcli/starskywebhtmlcli.csproj index 89d716fd9f..e8d9a161fd 100644 --- a/starsky/starskywebhtmlcli/starskywebhtmlcli.csproj +++ b/starsky/starskywebhtmlcli/starskywebhtmlcli.csproj @@ -17,6 +17,7 @@ + From a0624d99de91bdd8544fd7ed13f0202775fc2849 Mon Sep 17 00:00:00 2001 From: Dion Date: Thu, 14 Mar 2024 22:17:37 +0100 Subject: [PATCH 3/5] more clear --- starsky/starsky.foundation.platform/Services/WebLogger.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/starsky/starsky.foundation.platform/Services/WebLogger.cs b/starsky/starsky.foundation.platform/Services/WebLogger.cs index dd663d51ae..3a18785e29 100644 --- a/starsky/starsky.foundation.platform/Services/WebLogger.cs +++ b/starsky/starsky.foundation.platform/Services/WebLogger.cs @@ -4,7 +4,6 @@ using Microsoft.Extensions.Logging; using starsky.foundation.injection; using starsky.foundation.platform.Interfaces; -using starsky.foundation.platform.Models; namespace starsky.foundation.platform.Services { @@ -26,8 +25,10 @@ public WebLogger(ILoggerFactory? loggerFactory = null, IServiceScopeFactory? sco { _logger = loggerFactory?.CreateLogger("app"); var scopeProvider = scopeFactory?.CreateScope().ServiceProvider; - if ( scopeProvider == null ) return; - _console = scopeProvider.GetService(); + if ( scopeProvider != null ) + { + _console = scopeProvider.GetService(); + } } public void LogDebug(string? message, params object[] args) From 4ca9cd3883fc199976dff2a16bb09e75f33a869e Mon Sep 17 00:00:00 2001 From: Dion Date: Thu, 14 Mar 2024 22:19:34 +0100 Subject: [PATCH 4/5] try this --- .../starsky.foundation.sync/SyncServices/SyncSingleFile.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/starsky/starsky.foundation.sync/SyncServices/SyncSingleFile.cs b/starsky/starsky.foundation.sync/SyncServices/SyncSingleFile.cs index fb87f2211f..64828a317c 100644 --- a/starsky/starsky.foundation.sync/SyncServices/SyncSingleFile.cs +++ b/starsky/starsky.foundation.sync/SyncServices/SyncSingleFile.cs @@ -71,8 +71,9 @@ internal async Task> SingleFile(string subPath, if ( statusItems.FirstOrDefault()!.Status != FileIndexItem.ExifStatus.Ok ) { - _logger.LogDebug($"[SingleFile/db] status " + - $"{statusItems.FirstOrDefault()!.Status} for {subPath} {Synchronize.DateTimeDebug()}"); + _logger.LogDebug("[SingleFile/db] status " + + "{Status} for {subPath} {Time}", + statusItems.FirstOrDefault()!.Status, Synchronize.DateTimeDebug()); return statusItems; } From be9c2e4f722a4123f588e5144e196ab9ea7ca4b9 Mon Sep 17 00:00:00 2001 From: Dion Date: Fri, 15 Mar 2024 08:29:18 +0100 Subject: [PATCH 5/5] This avoid errors --- .../starsky.foundation.platform/Helpers/FilenamesHelper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/starsky/starsky.foundation.platform/Helpers/FilenamesHelper.cs b/starsky/starsky.foundation.platform/Helpers/FilenamesHelper.cs index f652d6f941..13ace1fc12 100644 --- a/starsky/starsky.foundation.platform/Helpers/FilenamesHelper.cs +++ b/starsky/starsky.foundation.platform/Helpers/FilenamesHelper.cs @@ -64,7 +64,7 @@ public static string GetFileName(string filePath, /// Regex object [GeneratedRegex( "\\.[a-zA-Z0-9]{1,4}$", - RegexOptions.NonBacktracking, + RegexOptions.None, matchTimeoutMilliseconds: 100)] private static partial Regex FileNameWithoutExtensionRegex(); @@ -88,7 +88,7 @@ public static string GetFileNameWithoutExtension(string filePath) /// Regex object [GeneratedRegex( "[^.][a-zA-Z0-9]{1,4}$", - RegexOptions.NonBacktracking, + RegexOptions.None, matchTimeoutMilliseconds: 100)] private static partial Regex FileExtensionWithoutDotRegex();