Skip to content

Commit

Permalink
ASP.NET logger includes specific SlackNet category in logs
Browse files Browse the repository at this point in the history
Allows categories to be enabled separately via logger config
  • Loading branch information
soxtoby committed Aug 10, 2023
1 parent fef28c0 commit 5f8d6e4
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions SlackNet.AspNetCore/MicrosoftLoggerAdaptor.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
using Microsoft.Extensions.Logging;
using SlackNetLogger = SlackNet.ILogger;
using MicrosoftLogger = Microsoft.Extensions.Logging.ILogger;

namespace SlackNet.AspNetCore;

class MicrosoftLoggerAdaptor : SlackNetLogger
{
private readonly MicrosoftLogger _logger;
public MicrosoftLoggerAdaptor(ILoggerFactory loggerFactory) => _logger = loggerFactory.CreateLogger("SlackNet");
private readonly ILoggerFactory _loggerFactory;
public MicrosoftLoggerAdaptor(ILoggerFactory loggerFactory) => _loggerFactory = loggerFactory;

public void Log(ILogEvent logEvent) =>
_logger.Log(logEvent.Category switch
_loggerFactory
.CreateLogger($"SlackNet.{logEvent.Category}")
.Log(logEvent.Category switch
{
LogCategory.Data => LogLevel.Trace,
LogCategory.Serialization => LogLevel.Trace,
LogCategory.Internal => LogLevel.Debug,
LogCategory.Request => LogLevel.Information,
LogCategory.Error => LogLevel.Error,
Expand Down

0 comments on commit 5f8d6e4

Please sign in to comment.