chore(deps): update dependency nlog.web.aspnetcore to v6 (#3438)

* chore(deps): update dependency nlog.web.aspnetcore to v6

* Adapt ASF to NLog v6

* Use another approach for NLog file archiving

* Use cached ${currentdir} to improve performance

* Misc fix

* Update suffix format

* Misc

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Łukasz Domeradzki <JustArchi@JustArchi.net>
This commit is contained in:
renovate[bot]
2025-07-05 15:39:37 +02:00
committed by GitHub
parent e93ea74def
commit 4ba034f988
6 changed files with 25 additions and 18 deletions

View File

@@ -207,6 +207,7 @@ internal static class Logging {
internal static void InitCoreLoggers(bool uniqueInstance) {
try {
// Handle edge case of user using NLog.config in non-standard directory (current directory)
if ((Directory.GetCurrentDirectory() != AppContext.BaseDirectory) && File.Exists(NLogConfigurationFile)) {
IsUsingCustomConfiguration = true;
@@ -224,6 +225,11 @@ internal static class Logging {
}
if (uniqueInstance) {
if (LogManager.Configuration == null) {
// This should never happen, as configuration must be initialized by now (either by user's config, InitEmergencyLoggers() or InitCoreLoggers() above)
throw new InvalidOperationException(nameof(LogManager.Configuration));
}
try {
Directory.CreateDirectory(SharedInfo.ArchivalLogsDirectory);
} catch (Exception e) {
@@ -232,12 +238,10 @@ internal static class Logging {
#pragma warning disable CA2000 // False positive, we're adding this disposable object to the global scope, so we can't dispose it
FileTarget fileTarget = new("File") {
ArchiveFileName = Path.Combine("${currentdir}", SharedInfo.ArchivalLogsDirectory, SharedInfo.ArchivalLogFile),
ArchiveNumbering = ArchiveNumberingMode.Rolling,
ArchiveFileName = Path.Combine("${currentdir:cached=true}", SharedInfo.ArchivalLogsDirectory, SharedInfo.LogFile),
ArchiveOldFileOnStartup = true,
CleanupFileName = false,
DeleteOldFileOnStartup = true,
FileName = Path.Combine("${currentdir}", SharedInfo.LogFile),
ArchiveSuffixFormat = ".{1:yyyyMMdd-HHmmss}",
FileName = Path.Combine("${currentdir:cached=true}", SharedInfo.LogFile),
// Windows OS prevents other apps from reading file when actively holding exclusive (write) lock over it
// We require read access for GET /Api/NLog/File ASF API usage, therefore we shouldn't keep the lock all the time
@@ -265,6 +269,7 @@ internal static class Logging {
// This is a temporary, bare, file-less configuration that must work until we're able to initialize it properly
ConfigurationItemFactory.Default.ParseMessageTemplates = false;
LoggingConfiguration config = new();
#pragma warning disable CA2000 // False positive, we're adding this disposable object to the global scope, so we can't dispose it

View File

@@ -31,10 +31,8 @@ using NLog.Targets;
namespace ArchiSteamFarm.NLog.Targets;
[Target(TargetName)]
[Target("History")]
internal sealed class HistoryTarget : TargetWithLayout {
internal const string TargetName = "History";
private const byte DefaultMaxCount = 20;
internal IEnumerable<string> ArchivedMessages => HistoryQueue;

View File

@@ -30,17 +30,15 @@ using ArchiSteamFarm.Localization;
using ArchiSteamFarm.Steam;
using JetBrains.Annotations;
using NLog;
using NLog.Config;
using NLog.Layouts;
using NLog.Targets;
using SteamKit2;
namespace ArchiSteamFarm.NLog.Targets;
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")]
[Target(TargetName)]
[Target("Steam")]
internal sealed class SteamTarget : AsyncTaskTarget {
internal const string TargetName = "Steam";
// This is NLog config property, it must have public get() and set() capabilities
[UsedImplicitly]
public Layout? BotName { get; set; }
@@ -50,7 +48,6 @@ internal sealed class SteamTarget : AsyncTaskTarget {
public ulong ChatGroupID { get; set; }
// This is NLog config property, it must have public get() and set() capabilities
[RequiredParameter]
[UsedImplicitly]
public ulong SteamID { get; set; }
@@ -59,12 +56,20 @@ internal sealed class SteamTarget : AsyncTaskTarget {
// Keeping date in default layout also doesn't make much sense (Steam offers that), so we remove it by default
public SteamTarget() => Layout = "${level:uppercase=true}|${logger}|${message}";
protected override void InitializeTarget() {
base.InitializeTarget();
if ((SteamID == 0) || ((ChatGroupID == 0) && !new SteamID(SteamID).IsIndividualAccount)) {
throw new NLogConfigurationException(Strings.FormatErrorIsInvalid(nameof(SteamID)));
}
}
protected override async Task WriteAsyncTask(LogEventInfo logEvent, CancellationToken cancellationToken) {
ArgumentNullException.ThrowIfNull(logEvent);
Write(logEvent);
if ((SteamID == 0) || (Bot.Bots == null) || Bot.Bots.IsEmpty) {
if ((Bot.Bots == null) || Bot.Bots.IsEmpty) {
return;
}

View File

@@ -188,8 +188,8 @@ internal static class Program {
// Add support for custom logging targets
LogManager.Setup().SetupExtensions(static extensions => {
extensions.RegisterTarget<HistoryTarget>(HistoryTarget.TargetName);
extensions.RegisterTarget<SteamTarget>(SteamTarget.TargetName);
extensions.RegisterTarget<HistoryTarget>();
extensions.RegisterTarget<SteamTarget>();
}
);

View File

@@ -35,7 +35,6 @@ public static class SharedInfo {
[PublicAPI]
public const string ConfigDirectory = "config";
internal const string ArchivalLogFile = "log.{#}.txt";
internal const string ArchivalLogsDirectory = "logs";
internal const string ASF = nameof(ASF);
internal const ulong ASFGroupSteamID = 103582791440160998;

View File

@@ -10,7 +10,7 @@
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="8.12.1" />
<PackageVersion Include="MSTest" Version="3.9.3" />
<PackageVersion Include="Nito.AsyncEx.Coordination" Version="5.1.2" />
<PackageVersion Include="NLog.Web.AspNetCore" Version="5.5.0" />
<PackageVersion Include="NLog.Web.AspNetCore" Version="6.0.0" />
<PackageVersion Include="OpenTelemetry.Exporter.Prometheus.AspNetCore" Version="1.9.0-beta.2" />
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.12.0" />