logging changes
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<PropertyGroup>
|
||||
<!--package info-->
|
||||
<PackageId>DTLib.Logging</PackageId>
|
||||
<Version>1.2.1</Version>
|
||||
<Version>1.3.0</Version>
|
||||
<Authors>Timerix</Authors>
|
||||
<Description>Loggers with dependency injection</Description>
|
||||
<RepositoryType>GIT</RepositoryType>
|
||||
@@ -30,7 +30,7 @@
|
||||
<ProjectReference Include="..\DTLib.Ben.Demystifier\DTLib.Ben.Demystifier.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
|
||||
<PackageReference Include="DTLib" Version="1.2.2" />
|
||||
<PackageReference Include="DTLib" Version="1.3.0" />
|
||||
<PackageReference Include="DTLib.Ben.Demystifier" Version="1.0.4" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace DTLib.Logging.DependencyInjection;
|
||||
public class LoggerService<TCaller> : 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<TCaller>),
|
||||
new MyLoggerWrapper<TCaller>(logger))
|
||||
{
|
||||
|
||||
@@ -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<TCaller> : Microsoft.Extensions.Logging.ILogger<TCaller>
|
||||
{
|
||||
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<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace DTLib.Logging.New;
|
||||
namespace DTLib.Logging;
|
||||
|
||||
public interface ILogFormat
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace DTLib.Logging.New;
|
||||
namespace DTLib.Logging;
|
||||
|
||||
public enum LogSeverity
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using DTLib.Ben.Demystifier;
|
||||
|
||||
namespace DTLib.Logging.New;
|
||||
namespace DTLib.Logging;
|
||||
|
||||
public static class LoggerExtensions
|
||||
{
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
namespace DTLib.Logging.New;
|
||||
namespace DTLib.Logging;
|
||||
|
||||
/// <summary>
|
||||
/// 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 =
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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; }
|
||||
|
||||
@@ -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; }
|
||||
|
||||
Reference in New Issue
Block a user