2024-08-28 20:33:59 -05:00
|
|
|
|
/*
|
|
|
|
|
|
using NLog;
|
2024-01-29 22:29:47 -06:00
|
|
|
|
using NLog.Config;
|
|
|
|
|
|
using NLog.Targets;
|
|
|
|
|
|
|
|
|
|
|
|
namespace LANCommander.Logging
|
|
|
|
|
|
{
|
|
|
|
|
|
[Target("LoggingHub")]
|
|
|
|
|
|
public class LoggingHubTarget : AsyncTaskTarget
|
|
|
|
|
|
{
|
|
|
|
|
|
private LoggingHubConnection? Connection;
|
|
|
|
|
|
|
|
|
|
|
|
[RequiredParameter]
|
|
|
|
|
|
public string HubUrl { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
protected override void InitializeTarget()
|
|
|
|
|
|
{
|
|
|
|
|
|
Connection = new LoggingHubConnection(HubUrl);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override async Task WriteAsyncTask(LogEventInfo logEvent, CancellationToken token)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Connection != null)
|
|
|
|
|
|
await Connection.Log(Layout.Render(logEvent));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override async void CloseTarget()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Connection != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
await Connection.DisposeAsync();
|
|
|
|
|
|
Connection = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-08-28 20:33:59 -05:00
|
|
|
|
*/
|