Skip to content

Commit

Permalink
chore(deps): update dependency log4net to v3 (#1201)
Browse files Browse the repository at this point in the history
* chore(deps): update dependency log4net to v3

* fix nullable build errors

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: David Vreony <dpvreony@users.noreply.github.com>
  • Loading branch information
renovate[bot] and dpvreony authored Sep 28, 2024
1 parent 6339c05 commit f7f499d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
<PackageVersion Include="DryIoc.Dll" Version="5.4.3" />
<PackageVersion Include="Exceptionless" Version="6.0.4" />
<PackageVersion Include="log4net" Version="2.0.17" />
<PackageVersion Include="log4net" Version="3.0.0" />
<PackageVersion Include="Microsoft.AppCenter.Analytics" Version="5.0.5" />
<PackageVersion Include="Microsoft.AppCenter.Crashes" Version="5.0.5" />
<PackageVersion Include="Microsoft.ApplicationInsights" Version="2.22.0" />
Expand Down
7 changes: 6 additions & 1 deletion src/Splat.Log4Net/Log4NetLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ public sealed class Log4NetLogger : ILogger, IDisposable
public Log4NetLogger(global::log4net.ILog inner)
{
_inner = inner ?? throw new ArgumentNullException(nameof(inner));
if (_inner.Logger.Repository == null)
{
throw new ArgumentException("Log4Net is not correctly initialized. It's not exposing a Logger repository to splat.", nameof(inner));
}

SetLogLevel();
_inner.Logger.Repository.ConfigurationChanged += OnInnerLoggerReconfigured;
}
Expand All @@ -31,7 +36,7 @@ public Log4NetLogger(global::log4net.ILog inner)
public LogLevel Level { get; private set; }

/// <inheritdoc />
public void Dispose() => _inner.Logger.Repository.ConfigurationChanged -= OnInnerLoggerReconfigured;
public void Dispose() => _inner.Logger.Repository!.ConfigurationChanged -= OnInnerLoggerReconfigured;

/// <inheritdoc />
public void Write(string message, LogLevel logLevel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ private sealed class MemoryTargetWrapper(global::log4net.Appender.MemoryAppender
MemoryTarget.Flush(0);
return MemoryTarget.GetEvents().Select(x =>
{
var currentLevel = _log4Net2Splat[x.Level];
var currentLevel = _log4Net2Splat.GetValueOrDefault(x.Level ?? Level.Debug, LogLevel.Debug);

return x.ExceptionObject switch
{
not null => (currentLevel, $"{x.MessageObject} {x.ExceptionObject}"),
_ => (currentLevel, x.MessageObject.ToString()!)
_ => (currentLevel, x.MessageObject?.ToString() ?? string.Empty)
};
}).ToList();
}
Expand Down

0 comments on commit f7f499d

Please sign in to comment.