From 6c8454b741e2e5d3b84e05625013392c906e6587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=E2=96=88=E2=96=88=E2=96=88=E2=96=88=E2=96=88?= Date: Mon, 21 Oct 2024 16:44:56 -0400 Subject: [PATCH] Converting missed microsoft logger references to log4net Previous work in: 281101c1c46658f22a27f097405438cb74027fc0 --- .../Controllers/BotController.cs | 8 ++++---- .../Controllers/LoginController.cs | 8 ++++---- .../Nullinside.Api.TwitchBot.csproj | 2 +- .../Services/MainService.cs | 16 ++++++++-------- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Nullinside.Api.TwitchBot/Controllers/BotController.cs b/src/Nullinside.Api.TwitchBot/Controllers/BotController.cs index 328119b..52d5815 100644 --- a/src/Nullinside.Api.TwitchBot/Controllers/BotController.cs +++ b/src/Nullinside.Api.TwitchBot/Controllers/BotController.cs @@ -1,5 +1,7 @@ using System.Security.Claims; +using log4net; + using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -32,16 +34,14 @@ public class BotController : ControllerBase { /// /// The logger. /// - private readonly ILogger _logger; + private readonly ILog _log = LogManager.GetLogger(typeof(BotController)); /// /// Initializes a new instance of the class. /// - /// The logger. /// The nullinside database. /// The application's configuration. - public BotController(ILogger logger, NullinsideContext dbContext, IConfiguration configuration) { - _logger = logger; + public BotController(NullinsideContext dbContext, IConfiguration configuration) { _dbContext = dbContext; _configuration = configuration; } diff --git a/src/Nullinside.Api.TwitchBot/Controllers/LoginController.cs b/src/Nullinside.Api.TwitchBot/Controllers/LoginController.cs index a2ea069..07dc383 100644 --- a/src/Nullinside.Api.TwitchBot/Controllers/LoginController.cs +++ b/src/Nullinside.Api.TwitchBot/Controllers/LoginController.cs @@ -1,3 +1,5 @@ +using log4net; + using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -26,16 +28,14 @@ public class LoginController : ControllerBase { /// /// The logger. /// - private readonly ILogger _logger; + private readonly ILog _log = LogManager.GetLogger(typeof(LoginController)); /// /// Initializes a new instance of the class. /// - /// The logger. /// The nullinside database. /// The application's configuration. - public LoginController(ILogger logger, NullinsideContext dbContext, IConfiguration configuration) { - _logger = logger; + public LoginController(NullinsideContext dbContext, IConfiguration configuration) { _dbContext = dbContext; _configuration = configuration; } diff --git a/src/Nullinside.Api.TwitchBot/Nullinside.Api.TwitchBot.csproj b/src/Nullinside.Api.TwitchBot/Nullinside.Api.TwitchBot.csproj index facee58..b3f5528 100644 --- a/src/Nullinside.Api.TwitchBot/Nullinside.Api.TwitchBot.csproj +++ b/src/Nullinside.Api.TwitchBot/Nullinside.Api.TwitchBot.csproj @@ -23,7 +23,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Nullinside.Api.TwitchBot/Services/MainService.cs b/src/Nullinside.Api.TwitchBot/Services/MainService.cs index 5ed4c89..a41d15e 100644 --- a/src/Nullinside.Api.TwitchBot/Services/MainService.cs +++ b/src/Nullinside.Api.TwitchBot/Services/MainService.cs @@ -1,5 +1,7 @@ using System.Collections.Concurrent; +using log4net; + using Microsoft.EntityFrameworkCore; using Nullinside.Api.Common.Twitch; @@ -42,7 +44,7 @@ public class MainService : BackgroundService { /// /// The logger. /// - private readonly ILogger _log; + private readonly ILog _log = LogManager.GetLogger(typeof(MainService)); /// /// A collection of all bans received. @@ -80,10 +82,8 @@ public class MainService : BackgroundService { /// /// Initializes a new instance of the class. /// - /// The logger. /// The service scope factory. - public MainService(ILogger logger, IServiceScopeFactory serviceScopeFactory) { - _log = logger; + public MainService(IServiceScopeFactory serviceScopeFactory) { _serviceScopeFactory = serviceScopeFactory; _scope = _serviceScopeFactory.CreateScope(); _db = _scope.ServiceProvider.GetRequiredService(); @@ -116,7 +116,7 @@ protected override Task ExecuteAsync(CancellationToken stoppingToken) { await Main(stoppingToken); } catch (Exception ex) { - _log.LogError(ex, "Main Failed"); + _log.Error("Main Failed", ex); await Task.Delay(TimeSpan.FromSeconds(10), stoppingToken); } } @@ -179,7 +179,7 @@ private async Task Main(CancellationToken stoppingToken) { await DoScan(user, botUser, stoppingToken); } catch (Exception ex) { - _log.LogError(ex, $"Scan failed for {user.TwitchUsername}"); + _log.Error($"Scan failed for {user.TwitchUsername}", ex); } }); } @@ -190,7 +190,7 @@ private async Task Main(CancellationToken stoppingToken) { } } catch (Exception ex) { - _log.LogError(ex, "Main Inner failed"); + _log.Error("Main Inner failed", ex); } } @@ -297,7 +297,7 @@ private async Task DoScan(User user, User botUser, CancellationToken stoppingTok } } catch (Exception e) { - _log.LogError(e, $"{user.TwitchUsername}: Failed to evaluate rule"); + _log.Error($"{user.TwitchUsername}: Failed to evaluate rule", e); } }