diff --git a/DTLib.Dtsod/DTLib.Dtsod.csproj b/DTLib.Dtsod/DTLib.Dtsod.csproj index a17a3c1..7598b4e 100644 --- a/DTLib.Dtsod/DTLib.Dtsod.csproj +++ b/DTLib.Dtsod/DTLib.Dtsod.csproj @@ -2,7 +2,7 @@ DTLib.Dtsod - 1.2.1 + 1.3.0 Timerix Definitely not json GIT @@ -33,7 +33,7 @@ - + diff --git a/DTLib.Dtsod/IDtsod.cs b/DTLib.Dtsod/IDtsod.cs index 443ffbf..314b28a 100644 --- a/DTLib.Dtsod/IDtsod.cs +++ b/DTLib.Dtsod/IDtsod.cs @@ -4,7 +4,7 @@ global using System.Collections.Generic; global using System.Linq; global using System.Text; global using DTLib.Extensions; -global using static DTLib.Logging.PublicLog; +global using static DTLib.Logging.InternalLog; namespace DTLib.Dtsod; diff --git a/DTLib.Logging/DTLib.Logging.csproj b/DTLib.Logging/DTLib.Logging.csproj index b6da5e6..8a5d63b 100644 --- a/DTLib.Logging/DTLib.Logging.csproj +++ b/DTLib.Logging/DTLib.Logging.csproj @@ -2,7 +2,7 @@ DTLib.Logging - 1.2.1 + 1.3.0 Timerix Loggers with dependency injection GIT @@ -30,7 +30,7 @@ - + diff --git a/DTLib.Logging/DTLibInternalLogging.cs b/DTLib.Logging/DTLibInternalLogging.cs index ca38f5d..a2cd523 100644 --- a/DTLib.Logging/DTLibInternalLogging.cs +++ b/DTLib.Logging/DTLibInternalLogging.cs @@ -8,7 +8,7 @@ global using System.Threading.Tasks; global using DTLib.Extensions; global using DTLib.Filesystem; -namespace DTLib.Logging.New; +namespace DTLib.Logging; /// this class can be used to setup logger for DTLib debug log messages public static class DTLibInternalLogging @@ -18,7 +18,7 @@ public static class DTLibInternalLogging public static void SetLogger(ILogger logger) { _loggerContext = new ContextLogger("DTLib",logger); - PublicLog.LogEvent+=LogHandler; + InternalLog.LogEvent+=LogHandler; } private static void LogHandler(string[] msg) diff --git a/DTLib.Logging/DependencyInjection/LoggerService.cs b/DTLib.Logging/DependencyInjection/LoggerService.cs index bbe9669..a7bde81 100644 --- a/DTLib.Logging/DependencyInjection/LoggerService.cs +++ b/DTLib.Logging/DependencyInjection/LoggerService.cs @@ -5,7 +5,7 @@ namespace DTLib.Logging.DependencyInjection; public class LoggerService : ServiceDescriptor { // ReSharper disable once RedundantNameQualifier - public LoggerService(DTLib.Logging.New.ILogger logger) : base( + public LoggerService(DTLib.Logging.ILogger logger) : base( typeof(Microsoft.Extensions.Logging.ILogger), new MyLoggerWrapper(logger)) { diff --git a/DTLib.Logging/DependencyInjection/MyLoggerWrapper.cs b/DTLib.Logging/DependencyInjection/MyLoggerWrapper.cs index 885b028..653f127 100644 --- a/DTLib.Logging/DependencyInjection/MyLoggerWrapper.cs +++ b/DTLib.Logging/DependencyInjection/MyLoggerWrapper.cs @@ -1,4 +1,4 @@ -using DTLib.Logging.New; +using DTLib.Logging; using Microsoft.Extensions.Logging; // ReSharper disable RedundantNameQualifier @@ -6,8 +6,8 @@ namespace DTLib.Logging.DependencyInjection; public class MyLoggerWrapper : Microsoft.Extensions.Logging.ILogger { - public DTLib.Logging.New.ILogger Logger; - public MyLoggerWrapper(DTLib.Logging.New.ILogger logger)=> + public DTLib.Logging.ILogger Logger; + public MyLoggerWrapper(DTLib.Logging.ILogger logger)=> Logger = logger; public void Log(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func formatter) diff --git a/DTLib.Logging/LogFormats/DefaultLogFormat.cs b/DTLib.Logging/LogFormats/DefaultLogFormat.cs index 586d341..0807df0 100644 --- a/DTLib.Logging/LogFormats/DefaultLogFormat.cs +++ b/DTLib.Logging/LogFormats/DefaultLogFormat.cs @@ -1,4 +1,4 @@ -namespace DTLib.Logging.New; +namespace DTLib.Logging; public class DefaultLogFormat : ILogFormat { @@ -7,7 +7,7 @@ public class DefaultLogFormat : ILogFormat public bool PrintContext { get; set; } public bool PrintSeverity { get; set; } - public DefaultLogFormat(bool printTimeStamp = false, bool printContext = true, bool printSeverity = true) + public DefaultLogFormat(bool printTimeStamp = true, bool printContext = true, bool printSeverity = true) { PrintTimeStamp = printTimeStamp; PrintContext = printContext; diff --git a/DTLib.Logging/LogFormats/ILogFormat.cs b/DTLib.Logging/LogFormats/ILogFormat.cs index 3b1834f..caa8321 100644 --- a/DTLib.Logging/LogFormats/ILogFormat.cs +++ b/DTLib.Logging/LogFormats/ILogFormat.cs @@ -1,4 +1,4 @@ -namespace DTLib.Logging.New; +namespace DTLib.Logging; public interface ILogFormat { diff --git a/DTLib.Logging/LogSeverity.cs b/DTLib.Logging/LogSeverity.cs index e60fb92..fecffb5 100644 --- a/DTLib.Logging/LogSeverity.cs +++ b/DTLib.Logging/LogSeverity.cs @@ -1,4 +1,4 @@ -namespace DTLib.Logging.New; +namespace DTLib.Logging; public enum LogSeverity { diff --git a/DTLib.Logging/LoggerExtensions.cs b/DTLib.Logging/LoggerExtensions.cs index 2050000..a49e0af 100644 --- a/DTLib.Logging/LoggerExtensions.cs +++ b/DTLib.Logging/LoggerExtensions.cs @@ -1,6 +1,6 @@ using DTLib.Ben.Demystifier; -namespace DTLib.Logging.New; +namespace DTLib.Logging; public static class LoggerExtensions { diff --git a/DTLib.Logging/Loggers/CompositeLogger.cs b/DTLib.Logging/Loggers/CompositeLogger.cs index 1cf613d..a4e0323 100644 --- a/DTLib.Logging/Loggers/CompositeLogger.cs +++ b/DTLib.Logging/Loggers/CompositeLogger.cs @@ -1,4 +1,4 @@ -namespace DTLib.Logging.New; +namespace DTLib.Logging; /// /// This class can be used for unite many loggers into one @@ -49,7 +49,7 @@ public class CompositeLogger : ILogger } } - public ILogFormat Format { get; } + public ILogFormat Format { get; set; } protected ILogger[] _loggers; private bool _debugLogEnabled = diff --git a/DTLib.Logging/Loggers/ConsoleLogger.cs b/DTLib.Logging/Loggers/ConsoleLogger.cs index fbd6f31..949f505 100644 --- a/DTLib.Logging/Loggers/ConsoleLogger.cs +++ b/DTLib.Logging/Loggers/ConsoleLogger.cs @@ -1,6 +1,6 @@ using DTLib.Console; -namespace DTLib.Logging.New; +namespace DTLib.Logging; // вывод лога в консоль и файл public class ConsoleLogger : ILogger @@ -14,7 +14,7 @@ public class ConsoleLogger : ILogger public bool InfoLogEnabled { get; set; } = true; public bool WarnLogEnabled { get; set; } = true; public bool ErrorLogEnabled { get; set; } = true; - public ILogFormat Format { get; } + public ILogFormat Format { get; set; } readonly object consolelocker = new(); diff --git a/DTLib.Logging/Loggers/ContextLogger.cs b/DTLib.Logging/Loggers/ContextLogger.cs index e9f7bcf..c015626 100644 --- a/DTLib.Logging/Loggers/ContextLogger.cs +++ b/DTLib.Logging/Loggers/ContextLogger.cs @@ -1,4 +1,4 @@ -namespace DTLib.Logging.New; +namespace DTLib.Logging; /// wrapper around ILogger and LoggerExtensions that stores context public class ContextLogger : ILogger @@ -50,7 +50,11 @@ public class ContextLogger : ILogger public void Dispose() => ParentLogger.Dispose(); - public ILogFormat Format => ParentLogger.Format; + public ILogFormat Format + { + get => ParentLogger.Format; + set => ParentLogger.Format=value; + } public bool DebugLogEnabled { diff --git a/DTLib.Logging/Loggers/FileLogger.cs b/DTLib.Logging/Loggers/FileLogger.cs index 7114e21..11babf5 100644 --- a/DTLib.Logging/Loggers/FileLogger.cs +++ b/DTLib.Logging/Loggers/FileLogger.cs @@ -1,4 +1,4 @@ -namespace DTLib.Logging.New; +namespace DTLib.Logging; public class FileLogger : ILogger { @@ -11,7 +11,7 @@ public class FileLogger : ILogger public bool InfoLogEnabled { get; set; } = true; public bool WarnLogEnabled { get; set; } = true; public bool ErrorLogEnabled { get; set; } = true; - public ILogFormat Format { get; } + public ILogFormat Format { get; set; } public IOPath LogfileName { get; protected set; } public System.IO.FileStream LogfileStream { get; protected set; } diff --git a/DTLib.Logging/Loggers/ILogger.cs b/DTLib.Logging/Loggers/ILogger.cs index 19c5622..d80c220 100644 --- a/DTLib.Logging/Loggers/ILogger.cs +++ b/DTLib.Logging/Loggers/ILogger.cs @@ -1,9 +1,9 @@ -namespace DTLib.Logging.New; +namespace DTLib.Logging; public interface ILogger : IDisposable { - ILogFormat Format { get; } + ILogFormat Format { get; set; } bool DebugLogEnabled { get; set; } bool InfoLogEnabled { get; set; } bool WarnLogEnabled { get; set; } diff --git a/DTLib.Network/DTLib.Network.csproj b/DTLib.Network/DTLib.Network.csproj index 2c64878..25c9a9a 100644 --- a/DTLib.Network/DTLib.Network.csproj +++ b/DTLib.Network/DTLib.Network.csproj @@ -2,7 +2,7 @@ DTLib.Network - 1.2.1 + 1.3.0 Timerix Some sick network protocols GIT @@ -32,6 +32,6 @@ - + diff --git a/DTLib.Network/OldNetwork.cs b/DTLib.Network/OldNetwork.cs index 6f96738..06aa6b8 100644 --- a/DTLib.Network/OldNetwork.cs +++ b/DTLib.Network/OldNetwork.cs @@ -6,7 +6,7 @@ global using System.Linq; global using System.Text; global using DTLib.Extensions; global using DTLib.Filesystem; -global using static DTLib.Logging.PublicLog; +global using static DTLib.Logging.InternalLog; using System.Diagnostics; using System.Net.Http; diff --git a/DTLib.Tests/DTLib.Tests.csproj b/DTLib.Tests/DTLib.Tests.csproj index e8670b7..f7a1936 100644 --- a/DTLib.Tests/DTLib.Tests.csproj +++ b/DTLib.Tests/DTLib.Tests.csproj @@ -27,10 +27,10 @@ - - - - + + + + diff --git a/DTLib.Tests/Dtsod/TestAutoarr.cs b/DTLib.Tests/Dtsod/TestAutoarr.cs index d25d732..d29a656 100644 --- a/DTLib.Tests/Dtsod/TestAutoarr.cs +++ b/DTLib.Tests/Dtsod/TestAutoarr.cs @@ -16,25 +16,25 @@ public static class TestAutoarr public static void Fill(Autoarr ar) { - OldLogger.Log("c", "----------[TestAutoarr/Fill]----------"); + Logger.Log("c", "----------[TestAutoarr/Fill]----------"); for(uint i=0;i ar) { - OldLogger.Log("c", "----------[TestAutoarr/Print]---------"); + Logger.Log("c", "----------[TestAutoarr/Print]---------"); foreach (KVPair pair in ar) - OldLogger.Log("h", pair.ToString()); - OldLogger.Log("g", "test completed"); + Logger.Log("h", pair.ToString()); + Logger.Log("g", "test completed"); } public static void Free(Autoarr ar) { - OldLogger.Log("c", "----------[TestAutoarr/Free]----------"); + Logger.Log("c", "----------[TestAutoarr/Free]----------"); ar.Dispose(); - OldLogger.Log("g", "test completed"); + Logger.Log("g", "test completed"); } } */ \ No newline at end of file diff --git a/DTLib.Tests/Dtsod/TestDtsodV23.cs b/DTLib.Tests/Dtsod/TestDtsodV23.cs index 82c5a33..9e9f2ca 100644 --- a/DTLib.Tests/Dtsod/TestDtsodV23.cs +++ b/DTLib.Tests/Dtsod/TestDtsodV23.cs @@ -16,73 +16,73 @@ public static class TestDtsodV23 public static void TestBaseTypes() { - OldLogger.Log("c", "-----[TestDtsodV23/TestBaseTypes]-----"); + ColoredConsole.WriteLine("c", "-----[TestDtsodV23/TestBaseTypes]-----"); DtsodV23 dtsod = new(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}base_types.dtsod")); foreach (var pair in dtsod) - OldLogger.Log("b", pair.Value.GetType().Name + ' ', "w", pair.Key + ' ', "c", pair.Value.ToString()); - OldLogger.Log("g", "test completed"); + ColoredConsole.WriteLine("b", pair.Value.GetType().Name + ' ', "w", pair.Key + ' ', "c", pair.Value.ToString()); + ColoredConsole.WriteLine("g", "test completed"); } public static void TestLists() { - OldLogger.Log("c", "-------[TestDtsodV23/TestLists]-------"); + ColoredConsole.WriteLine("c", "-------[TestDtsodV23/TestLists]-------"); DtsodV23 dtsod = new(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}lists.dtsod")); foreach (var pair in dtsod) { - OldLogger.Log("b", pair.Value.GetType().Name + ' ', "w", pair.Key, "c", + ColoredConsole.WriteLine("b", pair.Value.GetType().Name + ' ', "w", pair.Key, "c", $" count: {pair.Value.Count}"); foreach (var el in pair.Value) - OldLogger.Log("b", '\t'+el.GetType().Name + ' ', "c", el.ToString()); + ColoredConsole.WriteLine("b", '\t'+el.GetType().Name + ' ', "c", el.ToString()); } - OldLogger.Log("g", "test completed"); + ColoredConsole.WriteLine("g", "test completed"); } public static void TestComplexes() { - OldLogger.Log("c", "-----[TestDtsodV23/TestComplexes]-----"); + ColoredConsole.WriteLine("c", "-----[TestDtsodV23/TestComplexes]-----"); DtsodV23 dtsod = new(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}complexes.dtsod")); foreach (var complex in dtsod) { - OldLogger.Log("b", complex.Value.GetType().Name + ' ', "w", complex.Key, + ColoredConsole.WriteLine("b", complex.Value.GetType().Name + ' ', "w", complex.Key, "b", " size: ", "c", complex.Value.Keys.Count.ToString()); foreach (var pair in (DtsodV23) complex.Value) - OldLogger.Log("b", '\t' + pair.Value.GetType().Name + ' ', "w", pair.Key + ' ', + ColoredConsole.WriteLine("b", '\t' + pair.Value.GetType().Name + ' ', "w", pair.Key + ' ', "c", pair.Value.ToString()); } - OldLogger.Log("g", "test completed"); + ColoredConsole.WriteLine("g", "test completed"); } public static void TestReSerialization() { - OldLogger.Log("c", "--[TestDtsodV23/TestReSerialization]--"); + ColoredConsole.WriteLine("c", "--[TestDtsodV23/TestReSerialization]--"); var dtsod = new DtsodV23(new DtsodV23(new DtsodV23( new DtsodV23(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}complexes.dtsod")).ToString()).ToString()).ToString()); - OldLogger.Log("y", dtsod.ToString()); - OldLogger.Log("g", "test completed"); + ColoredConsole.WriteLine("y", dtsod.ToString()); + ColoredConsole.WriteLine("g", "test completed"); } public static void TestSpeed() { - OldLogger.Log("c", "-------[TestDtsodV23/TestSpeed]-------"); + ColoredConsole.WriteLine("c", "-------[TestDtsodV23/TestSpeed]-------"); IDtsod dtsod=null; string text = File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}messages.dtsod"); LogOperationTime("V21 deserialization",64,()=>dtsod=new DtsodV21(text)); LogOperationTime("V21 serialization", 64, () => _=dtsod.ToString()); LogOperationTime("V23 deserialization", 64, () => dtsod = new DtsodV23(text)); LogOperationTime("V23 serialization", 64, () => _ = dtsod.ToString()); - OldLogger.Log("g", "test completed"); + ColoredConsole.WriteLine("g", "test completed"); } public static void TestMemoryConsumption() { - OldLogger.Log("c", "----[TestDtsodV23/TestMemConsumpt]----"); + ColoredConsole.WriteLine("c", "----[TestDtsodV23/TestMemConsumpt]----"); string text = File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}messages.dtsod"); var a = GC.GetTotalMemory(true); var dtsods = new DtsodV23[64]; for (int i = 0; i < dtsods.Length; i++) dtsods[i] = new(text); var b = GC.GetTotalMemory(true); - OldLogger.Log("b", "at the start: ","c",$"{a/1024} kb\n", + ColoredConsole.WriteLine("b", "at the start: ","c",$"{a/1024} kb\n", "b", "at the end: ", "c", $"{b / 1024} kb\n{dtsods.Count()}","b"," dtsods initialized"); - OldLogger.Log("g", "test completed"); + ColoredConsole.WriteLine("g", "test completed"); } } diff --git a/DTLib.Tests/Dtsod/TestDtsodV24.cs b/DTLib.Tests/Dtsod/TestDtsodV24.cs index 9ad8eda..411f6ad 100644 --- a/DTLib.Tests/Dtsod/TestDtsodV24.cs +++ b/DTLib.Tests/Dtsod/TestDtsodV24.cs @@ -18,57 +18,57 @@ public static class TestDtsodV24 public static void TestBaseTypes() { - OldLogger.Log("c", "-----[TestDtsodV24/TestBaseTypes]-----"); + Logger.Log("c", "-----[TestDtsodV24/TestBaseTypes]-----"); DtsodV24 dtsod = new(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV24{Path.Sep}base_types.dtsod")); foreach (var pair in dtsod) - OldLogger.Log("b", pair.ToString()); - OldLogger.Log("g", "test completed"); + Logger.Log("b", pair.ToString()); + Logger.Log("g", "test completed"); } public static void TestComplexes() { - OldLogger.Log("c", "-----[TestDtsodV24/TestComplexes]-----"); + Logger.Log("c", "-----[TestDtsodV24/TestComplexes]-----"); DtsodV24 dtsod = new(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV24{Path.Sep}complexes.dtsod")); - OldLogger.Log("h", dtsod.ToString()); - OldLogger.Log("g", "test completed"); + Logger.Log("h", dtsod.ToString()); + Logger.Log("g", "test completed"); } public static void TestLists() { - OldLogger.Log("c", "-------[TestDtsodV24/TestLists]-------"); + Logger.Log("c", "-------[TestDtsodV24/TestLists]-------"); DtsodV24 dtsod = new(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV24{Path.Sep}lists.dtsod")); foreach (KVPair pair in dtsod) { var list = new Autoarr(pair.value.VoidPtr, false); - OldLogger.Log("b", pair.key.HGlobalUTF8ToString(), "w", $" length: {list.Length}"); + Logger.Log("b", pair.key.HGlobalUTF8ToString(), "w", $" length: {list.Length}"); foreach (var el in list) { - OldLogger.Log("h", '\t' + el.ToString()); + Logger.Log("h", '\t' + el.ToString()); if (el.TypeCode == KerepTypeCode.AutoarrUnitypePtr) { var ar = new Autoarr(el.VoidPtr, false); foreach (var k in ar) { - OldLogger.Log($"\t\t{k.ToString()}"); + Logger.Log($"\t\t{k.ToString()}"); } } } } - OldLogger.Log("g", "test completed"); + Logger.Log("g", "test completed"); } public static void TestReSerialization() { - OldLogger.Log("c", "--[TestDtsodV24/TestReSerialization]--"); + Logger.Log("c", "--[TestDtsodV24/TestReSerialization]--"); var dtsod = new DtsodV24(new DtsodV24(new DtsodV24( new DtsodV24(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV24{Path.Sep}complexes.dtsod")).ToString()).ToString()).ToString()); - OldLogger.Log("h", dtsod.ToString()); - OldLogger.Log("g", "test completed"); + Logger.Log("h", dtsod.ToString()); + Logger.Log("g", "test completed"); } public static void TestSpeed() { - OldLogger.Log("c", "-------[TestDtsodV24/TestSpeed]-------"); + Logger.Log("c", "-------[TestDtsodV24/TestSpeed]-------"); IDtsod dtsod=null; string _text = File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}messages.dtsod"); string text = ""; @@ -78,7 +78,7 @@ public static class TestDtsodV24 File.WriteAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV24{Path.Sep}messages.dtsod",text); LogOperationTime("V24 deserialization", 64, () => dtsod = new DtsodV24(text)); LogOperationTime("V24 serialization", 64, () => text = dtsod.ToString()); - OldLogger.Log("g", "test completed"); + Logger.Log("g", "test completed"); } } */ \ No newline at end of file diff --git a/DTLib.Tests/Dtsod/TestPInvoke.cs b/DTLib.Tests/Dtsod/TestPInvoke.cs index c24c392..6c57c3c 100644 --- a/DTLib.Tests/Dtsod/TestPInvoke.cs +++ b/DTLib.Tests/Dtsod/TestPInvoke.cs @@ -17,7 +17,7 @@ public static class TestPInvoke public static void TestUTF8() { - OldLogger.Log("c", "--------[TestPInvoke/TestUTF8]--------", "b", ""); + Logger.Log("c", "--------[TestPInvoke/TestUTF8]--------", "b", ""); IntPtr ptr; string str="_$\"\\\\'''\ta ыыы000;2;=:%d;```"; for(int i=0; i<1000; i++) @@ -25,7 +25,7 @@ public static class TestPInvoke ptr = Unmanaged.StringToHGlobalUTF8(str); str = Unmanaged.HGlobalUTF8ToString(ptr); } - OldLogger.Log("y", str); + Logger.Log("y", str); } [DllImport("kerep", CallingConvention = CallingConvention.Cdecl)] @@ -33,9 +33,9 @@ public static class TestPInvoke public static void TestPrintf() { - OldLogger.Log("c", "---------[TestPInvoke/Printf]---------", "b", ""); + Logger.Log("c", "---------[TestPInvoke/Printf]---------", "b", ""); pinvoke_print("ъъ~ 中文"); - OldLogger.Log("g", "test completed"); + Logger.Log("g", "test completed"); } [DllImport("kerep", CallingConvention = CallingConvention.Cdecl)] @@ -43,12 +43,12 @@ public static class TestPInvoke public static unsafe void TestMarshalling() { - OldLogger.Log("c", "---------[TestAutoarr/TestMarshalling]----------"); + Logger.Log("c", "---------[TestAutoarr/TestMarshalling]----------"); string msg = "ъъ~ 中文"; test_marshalling(msg, out var kptr); KVPair k = *(KVPair*)kptr; - OldLogger.Log("b", k.ToString()); - OldLogger.Log("g", "test completed"); + Logger.Log("b", k.ToString()); + Logger.Log("g", "test completed"); } } */ \ No newline at end of file diff --git a/DTLib.Tests/Program.cs b/DTLib.Tests/Program.cs index 32dfd7d..7717ab5 100644 --- a/DTLib.Tests/Program.cs +++ b/DTLib.Tests/Program.cs @@ -10,21 +10,24 @@ global using DTLib.Filesystem; global using DTLib.Dtsod; global using static DTLib.Tests.TesterLog; global using static DTLib.Tests.Program; -using DTLib.Console; -using DTLib.Logging.New; +global using DTLib.Console; +global using DTLib.Logging; namespace DTLib.Tests; public static class Program { - public static Logging.ConsoleLogger OldLogger = new("logs", "DTLib.Tests"); - public static ILogger Logger; + public static ILogger Logger = new CompositeLogger(new ConsoleLogger(), + new FileLogger("logs", "DTLib.Tests")) + + { + DebugLogEnabled = true + }; + public static void Main(string[] args) { System.Console.OutputEncoding = Encoding.UTF8; System.Console.InputEncoding = Encoding.UTF8; - Logger=new CompositeLogger(new ConsoleLogger(), - new FileLogger("logs", "DTLib.Tests")); var mainContext = new ContextLogger("Main", Logger); DTLibInternalLogging.SetLogger(Logger); diff --git a/DTLib.Tests/Tester.cs b/DTLib.Tests/Tester.cs index d868e1a..2214514 100644 --- a/DTLib.Tests/Tester.cs +++ b/DTLib.Tests/Tester.cs @@ -13,6 +13,6 @@ public static class TesterLog operation(); clock.Stop(); double time=(double)(clock.ElapsedTicks)/Stopwatch.Frequency/repeats; - PublicLog.Log("y",$"operation ","b",op_name,"y"," lasted ","b",time.ToString(MyTimeFormat.ForText),"y"," seconds"); + InternalLog.Log("y",$"operation ","b",op_name,"y"," lasted ","b",time.ToString(MyTimeFormat.ForText),"y"," seconds"); } } \ No newline at end of file diff --git a/DTLib/DTLib.csproj b/DTLib/DTLib.csproj index 079e973..fe21d0f 100644 --- a/DTLib/DTLib.csproj +++ b/DTLib/DTLib.csproj @@ -2,7 +2,7 @@ DTLib - 1.2.3 + 1.3.0 Timerix Library for all my C# projects GIT @@ -38,4 +38,7 @@ + + + diff --git a/DTLib/Extensions/BaseConverter.cs b/DTLib/Extensions/BaseConverter.cs index b9f7ee1..bca17ed 100644 --- a/DTLib/Extensions/BaseConverter.cs +++ b/DTLib/Extensions/BaseConverter.cs @@ -6,7 +6,7 @@ global using System.Text; global using System.Threading.Tasks; global using DTLib.Extensions; global using DTLib.Filesystem; -global using static DTLib.Logging.PublicLog; +global using static DTLib.Logging.InternalLog; using System.Globalization; using System.Runtime.CompilerServices; diff --git a/DTLib/Extensions/StringConverter.cs b/DTLib/Extensions/StringConverter.cs index f9fc8ca..c71dbbe 100644 --- a/DTLib/Extensions/StringConverter.cs +++ b/DTLib/Extensions/StringConverter.cs @@ -130,7 +130,7 @@ public static class StringConverter return o; } - // правильно реагирует на кавычки + /// правильно реагирует на кавычки public static List SplitToList(this string s, char c, char quot) { List output = new(); @@ -158,7 +158,7 @@ public static class StringConverter return output; } - // разбивает на части указанной длины + /// разбивает на части указанной длины public static List SplitToList(this string s, int length) { List parts = new(); diff --git a/DTLib/Hasher.cs b/DTLib/Hasher.cs index b82c46c..eb20f21 100644 --- a/DTLib/Hasher.cs +++ b/DTLib/Hasher.cs @@ -48,7 +48,7 @@ public class Hasher //var then = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; byte[] hash = xxh32.ComputeHash(fileStream); //var now = DateTime.Now.Hour * 3600 + DateTime.Now.Minute * 60 + DateTime.Now.Second; - //PublicLog.Log($"xxh32 hash: {hash.HashToString()} time: {now - then}"); + //InternalLog.Log($"xxh32 hash: {hash.HashToString()} time: {now - then}"); fileStream.Close(); return hash; } diff --git a/DTLib/Logging/PublicLog.cs b/DTLib/InternalLog.cs similarity index 90% rename from DTLib/Logging/PublicLog.cs rename to DTLib/InternalLog.cs index 3a0df2d..e186d78 100644 --- a/DTLib/Logging/PublicLog.cs +++ b/DTLib/InternalLog.cs @@ -3,7 +3,7 @@ /// /// вывод логов со всех классов в библиотеке /// -public static class PublicLog +public static class InternalLog { public delegate void LogDelegate(params string[] msg); // вот к этому объекту подключайте методы для вывода логов diff --git a/DTLib/Logging/ConsoleLogger.cs b/DTLib/Logging/ConsoleLogger.cs deleted file mode 100644 index a0b15d2..0000000 --- a/DTLib/Logging/ConsoleLogger.cs +++ /dev/null @@ -1,31 +0,0 @@ -using DTLib.Console; - -namespace DTLib.Logging; - -// вывод лога в консоль и файл -public class ConsoleLogger : FileLogger -{ - public ConsoleLogger(string logfile) : base(logfile){} - public ConsoleLogger(string dir, string programName) : base(dir, programName) {} - - - readonly object consolelocker = new(); - - public override void Log(params string[] msg) - { - // write to file - base.Log(msg); - // append timestamp - var strb = new StringBuilder(); - strb.Append('[').Append(LastLogMessageTime).Append("]: "); - int index = msg.Length == 1 ? 0 : 1; - strb.Append(msg[index]); - msg[index] = strb.ToString(); - // write to console - lock (consolelocker) - { - ColoredConsole.Write(msg); - System.Console.WriteLine(); - } - } -} diff --git a/DTLib/Logging/FileLogger.cs b/DTLib/Logging/FileLogger.cs deleted file mode 100644 index 844a810..0000000 --- a/DTLib/Logging/FileLogger.cs +++ /dev/null @@ -1,51 +0,0 @@ -namespace DTLib.Logging; - -public class FileLogger : IDisposable -{ - public FileLogger(string logfile) - { - LogfileName = logfile; - LogfileStream = File.OpenAppend(logfile); - } - - public FileLogger(string dir, string programName) - : this($"{dir}{Path.Sep}{programName}_{DateTime.Now.ToString(MyTimeFormat.ForFileNames)}.log") { } - - public string LogfileName { get; protected set; } - public System.IO.FileStream LogfileStream { get; protected set; } - protected string LastLogMessageTime; - - - public virtual void Log(params string[] msg) - { - lock (LogfileStream) - { - LastLogMessageTime = DateTime.Now.ToString(MyTimeFormat.ForText); - LogfileStream.FluentWriteString("[") - .FluentWriteString(LastLogMessageTime) - .FluentWriteString("]: "); - if (msg.Length == 1) - LogfileStream.FluentWriteString(msg[0]); - else - { - var strb = new StringBuilder(); - for (ushort i = 1; i < msg.Length; i += 2) - strb.Append(msg[i]); - LogfileStream.FluentWriteString(strb.ToString()); - } - LogfileStream.FluentWriteString("\n").Flush(); - } - } - - public virtual void Dispose() - { - try - { - LogfileStream?.Flush(); - LogfileStream?.Close(); - } - catch (ObjectDisposedException) { } - } - - ~FileLogger() => Dispose(); -} diff --git a/KerepWrapper/KerepWrapper.csproj b/KerepWrapper/KerepWrapper.csproj index f0ffc8b..20a419f 100644 --- a/KerepWrapper/KerepWrapper.csproj +++ b/KerepWrapper/KerepWrapper.csproj @@ -35,7 +35,7 @@ - +