mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-05 08:30:18 +00:00
SteamTarget: Report Write() progress properly
Okay so this is a nasty one. If somebody has configured SteamTarget to notify about e.g. ASF crash, our LogManager.Flush() will NOT wait for that message to be sent before returning, as the Write() operation will return the moment it hits any async operation, at the very latest, the operation to write to a socket. Our expectation is that we want to send that message (emptying our logging queue) before actually shutting down the process, and for that we need that Write() operation to block until the request is actually sent. This is a quick fix for that while a pending rewrite for AsyncTaskTarget is in order - https://github.com/NLog/NLog/wiki/How-to-write-a-custom-async-target
This commit is contained in:
@@ -55,7 +55,7 @@ namespace ArchiSteamFarm.NLog {
|
||||
// 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 async void Write(LogEventInfo logEvent) {
|
||||
protected override void Write(LogEventInfo logEvent) {
|
||||
if (logEvent == null) {
|
||||
throw new ArgumentNullException(nameof(logEvent));
|
||||
}
|
||||
@@ -84,11 +84,10 @@ namespace ArchiSteamFarm.NLog {
|
||||
}
|
||||
}
|
||||
|
||||
if (ChatGroupID != 0) {
|
||||
await SendGroupMessage(message, bot).ConfigureAwait(false);
|
||||
} else if (bot?.SteamID != SteamID) {
|
||||
await SendPrivateMessage(message, bot).ConfigureAwait(false);
|
||||
}
|
||||
Task task = ChatGroupID == 0 ? SendPrivateMessage(message, bot) : SendGroupMessage(message, bot);
|
||||
|
||||
// TODO: Rewrite this into proper AsyncTaskTarget
|
||||
task.Wait();
|
||||
}
|
||||
|
||||
private async Task SendGroupMessage(string message, Bot? bot = null) {
|
||||
|
||||
Reference in New Issue
Block a user