adds ILogger
This commit is contained in:
parent
b750a0c66f
commit
bd410c500d
1 changed files with 6 additions and 1 deletions
|
|
@ -3,17 +3,20 @@ using System.Net.Http;
|
|||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Server.Logging;
|
||||
|
||||
namespace Server.Engines.Chat
|
||||
{
|
||||
public static class Discord
|
||||
{
|
||||
private static readonly HttpClient _httpClient = new();
|
||||
private static readonly ILogger _logger = LogFactory.GetLogger(typeof(Discord));
|
||||
private static string _webhookUrl;
|
||||
|
||||
public static void Configure()
|
||||
{
|
||||
_webhookUrl = ServerConfiguration.GetOrUpdateSetting("chatdiscord.webhookUrl", "DISCORD_CHANNEL_WEBHOOK");
|
||||
_logger.Information("Discord integration configured. Enabled: {Enabled}", IsEnabled);
|
||||
}
|
||||
|
||||
public static bool IsEnabled => !string.IsNullOrEmpty(_webhookUrl);
|
||||
|
|
@ -37,10 +40,12 @@ namespace Server.Engines.Chat
|
|||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
await _httpClient.PostAsync(_webhookUrl, content);
|
||||
|
||||
_logger.Debug("Discord message sent for channel {ChannelName} user {Username}", channelName, username);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"Discord webhook error for channel [{channelName}] {username}: {ex.Message}");
|
||||
_logger.Error(ex, "Discord webhook failed for channel {ChannelName} user {Username}", channelName, username);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue