changed LoggerExtensions

This commit is contained in:
Timerix22 2023-01-04 03:25:40 +06:00
parent 5f7aface7b
commit fa43c1877e
5 changed files with 17 additions and 7 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<!--package info--> <!--package info-->
<PackageId>DTLib.Logging</PackageId> <PackageId>DTLib.Logging</PackageId>
<Version>1.0.2</Version> <Version>1.0.3</Version>
<Authors>Timerix</Authors> <Authors>Timerix</Authors>
<Description>Loggers with dependency injection</Description> <Description>Loggers with dependency injection</Description>
<RepositoryType>GIT</RepositoryType> <RepositoryType>GIT</RepositoryType>

View File

@ -28,12 +28,17 @@ public class LoggerContext
public void LogWarn(object message) public void LogWarn(object message)
=> Logger.LogWarn(Context, message); => Logger.LogWarn(Context, message);
/// uses Ben.Demystifier to serialize exception
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void LogWarn(Exception ex)
=> Logger.LogWarn(Context, ex);
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void LogError(object message) public void LogError(object message)
=> Logger.LogError(Context, message); => Logger.LogError(Context, message);
/// uses Ben.Demystifier to serialize exception /// uses Ben.Demystifier to serialize exception
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public void LogException(Exception ex) public void LogError(Exception ex)
=> Logger.LogException(Context, ex); => Logger.LogError(Context, ex);
} }

View File

@ -22,6 +22,11 @@ public static class LoggerExtensions
public static void LogWarn(this ILogger logger, string context, object message) public static void LogWarn(this ILogger logger, string context, object message)
=> logger.Log(context, LogSeverity.Warn, message); => logger.Log(context, LogSeverity.Warn, message);
/// uses Ben.Demystifier to serialize exception
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogWarn(this ILogger logger, string context, Exception ex)
=> logger.Log(context, LogSeverity.Warn, ex.ToStringDemystified());
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogError(this ILogger logger, string context, object message) public static void LogError(this ILogger logger, string context, object message)
=> logger.Log(context, LogSeverity.Error, message); => logger.Log(context, LogSeverity.Error, message);
@ -29,6 +34,6 @@ public static class LoggerExtensions
/// uses Ben.Demystifier to serialize exception /// uses Ben.Demystifier to serialize exception
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void LogException(this ILogger logger, string context, Exception ex) public static void LogError(this ILogger logger, string context, Exception ex)
=> logger.Log(context, LogSeverity.Error, ex.Demystify()); => logger.Log(context, LogSeverity.Error, ex.ToStringDemystified());
} }

View File

@ -28,7 +28,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(Configuration)' != 'Debug' "> <ItemGroup Condition=" '$(Configuration)' != 'Debug' ">
<PackageReference Include="DTLib.Network" Version="1.0.2" /> <PackageReference Include="DTLib.Network" Version="1.0.2" />
<PackageReference Include="DTLib.Logging" Version="1.0.2" /> <PackageReference Include="DTLib.Logging" Version="1.0.3" />
</ItemGroup> </ItemGroup>
<!--project files--> <!--project files-->

View File

@ -33,7 +33,7 @@ public static class Program
TestDtsodV24.TestAll(); TestDtsodV24.TestAll();
} }
catch (Exception ex) catch (Exception ex)
{ NewLogger.LogException("Main", ex); } { NewLogger.LogError("Main", ex); }
Console.ResetColor(); Console.ResetColor();
} }
} }