diff --git a/DTLib.Logging/DTLib.Logging.csproj b/DTLib.Logging/DTLib.Logging.csproj index 7768884..d716e7e 100644 --- a/DTLib.Logging/DTLib.Logging.csproj +++ b/DTLib.Logging/DTLib.Logging.csproj @@ -2,7 +2,7 @@ DTLib.Logging - 1.0.4 + 1.0.5 Timerix Loggers with dependency injection GIT diff --git a/DTLib.Logging/DTLibInternalLogging.cs b/DTLib.Logging/DTLibInternalLogging.cs new file mode 100644 index 0000000..f16bd3a --- /dev/null +++ b/DTLib.Logging/DTLibInternalLogging.cs @@ -0,0 +1,37 @@ +global using System; +global using System.Collections; +global using System.Collections.Generic; +global using System.Runtime.CompilerServices; +global using System.Linq; +global using System.Text; +global using System.Threading.Tasks; +global using DTLib.Extensions; +global using DTLib.Filesystem; + +namespace DTLib.Logging.New; + +/// this class can be used to setup logger for DTLib debug log messages +public static class DTLibInternalLogging +{ + private static ContextLogger _loggerContext; + + public static void SetLogger(ILogger logger) + { + _loggerContext = new ContextLogger(logger, "DTLib"); + PublicLog.LogEvent+=LogHandler; + } + + private static void LogHandler(string[] msg) + { + if (msg.Length == 1) + { + _loggerContext.LogDebug(msg[0]); + return; + } + + StringBuilder b = new(); + for (int i = 1; i < msg.Length; i++) + b.Append(msg[i]); + _loggerContext.LogDebug(b.ToString()); + } +} \ No newline at end of file diff --git a/DTLib.Logging/Global.cs b/DTLib.Logging/Global.cs deleted file mode 100644 index 71451d6..0000000 --- a/DTLib.Logging/Global.cs +++ /dev/null @@ -1,12 +0,0 @@ -global using System; -global using System.Collections; -global using System.Collections.Generic; -global using System.Runtime.CompilerServices; -global using System.Linq; -global using System.Text; -global using System.Threading.Tasks; -global using DTLib.Extensions; -global using DTLib.Filesystem; - -namespace DTLib.Logging.New; - diff --git a/DTLib.Tests/DTLib.Tests.csproj b/DTLib.Tests/DTLib.Tests.csproj index e835374..ccef02c 100644 --- a/DTLib.Tests/DTLib.Tests.csproj +++ b/DTLib.Tests/DTLib.Tests.csproj @@ -28,11 +28,13 @@ - + + + diff --git a/DTLib.Tests/Program.cs b/DTLib.Tests/Program.cs index 419136f..918cfea 100644 --- a/DTLib.Tests/Program.cs +++ b/DTLib.Tests/Program.cs @@ -17,14 +17,17 @@ namespace DTLib.Tests; public static class Program { - public static readonly Logging.ConsoleLogger OldLogger = new("logs", "DTLib.Tests"); - public static readonly ILogger NewLogger = new CompositeLogger(new ConsoleLogger(), new FileLogger(OldLogger.LogfileName)); + public static Logging.ConsoleLogger OldLogger = new("logs", "DTLib.Tests"); + public static ILogger Logger; public static void Main() { - Logging.PublicLog.LogEvent += OldLogger.Log; Console.OutputEncoding = Encoding.UTF8; Console.InputEncoding = Encoding.UTF8; - Console.Title="tester"; + Logger=new CompositeLogger(new ConsoleLogger(), + new FileLogger("logs", "DTLib.Tests")); + var mainContext = new ContextLogger(Logger, "Main"); + DTLibInternalLogging.SetLogger(Logger); + try { TestPInvoke.TestAll(); @@ -33,7 +36,8 @@ public static class Program TestDtsodV24.TestAll(); } catch (Exception ex) - { NewLogger.LogError("Main", ex); } + { mainContext.LogError(ex); } + Console.ResetColor(); } } \ No newline at end of file