Rename to reflect use with game servers. Filter messages on server log page by the currently opened server.
This commit is contained in:
parent
e8456de2cb
commit
9fae96bc9e
6 changed files with 23 additions and 21 deletions
|
@ -1,12 +1,13 @@
|
|||
using Microsoft.AspNetCore.SignalR;
|
||||
using NLog;
|
||||
|
||||
namespace LANCommander.Hubs
|
||||
{
|
||||
public class LoggingHub : Hub
|
||||
public class GameServerHub : Hub
|
||||
{
|
||||
public void Log(string logMessage)
|
||||
public void Log(Guid serverId, string message)
|
||||
{
|
||||
Clients.All.SendAsync("Log", logMessage);
|
||||
Clients.All.SendAsync("Log", serverId, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using NLog;
|
||||
|
||||
namespace LANCommander.Logging
|
||||
{
|
||||
public class LoggingHubConnection : IAsyncDisposable
|
||||
public class GameServerHubConnection : IAsyncDisposable
|
||||
{
|
||||
private HubConnection? HubConnection;
|
||||
private string HubUrl;
|
||||
|
||||
public LoggingHubConnection(string hubUrl)
|
||||
public GameServerHubConnection(string hubUrl)
|
||||
{
|
||||
HubUrl = hubUrl;
|
||||
}
|
||||
|
||||
public async Task Log(string logMessage)
|
||||
public async Task Log(Guid serverId, string message)
|
||||
{
|
||||
await EnsureConnection();
|
||||
|
||||
if (HubConnection != null)
|
||||
await HubConnection.SendAsync("Log", logMessage);
|
||||
await HubConnection.SendAsync("Log", serverId, message);
|
||||
}
|
||||
|
||||
public async Task EnsureConnection()
|
|
@ -4,25 +4,23 @@ using NLog.Targets;
|
|||
|
||||
namespace LANCommander.Logging
|
||||
{
|
||||
[Target("LoggingHub")]
|
||||
public class LoggingHubTarget : AsyncTaskTarget
|
||||
[Target("GameServerHub")]
|
||||
public class GameServerHubTarget : AsyncTaskTarget
|
||||
{
|
||||
private LoggingHubConnection? Connection;
|
||||
private GameServerHubConnection? Connection;
|
||||
|
||||
[RequiredParameter]
|
||||
public string HubUrl { get; set; }
|
||||
|
||||
protected override void InitializeTarget()
|
||||
{
|
||||
Connection = new LoggingHubConnection(HubUrl);
|
||||
Connection = new GameServerHubConnection(HubUrl);
|
||||
}
|
||||
|
||||
protected override async Task WriteAsyncTask(LogEventInfo logEvent, CancellationToken token)
|
||||
{
|
||||
string message = Layout.Render(logEvent);
|
||||
|
||||
if (Connection != null)
|
||||
await Connection.Log(message);
|
||||
if (Connection != null && logEvent.Properties.ContainsKey("ServerId"))
|
||||
await Connection.Log((Guid)logEvent.Properties["ServerId"], logEvent.FormattedMessage);
|
||||
}
|
||||
|
||||
protected override async void CloseTarget()
|
|
@ -1,5 +1,6 @@
|
|||
@page "/Servers/{id:guid}/Logs"
|
||||
@using Microsoft.AspNetCore.SignalR.Client
|
||||
@using NLog;
|
||||
@using XtermBlazor
|
||||
@attribute [Authorize]
|
||||
@inject ServerService ServerService
|
||||
|
@ -23,12 +24,13 @@
|
|||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
HubConnection = new HubConnectionBuilder()
|
||||
.WithUrl(NavigationManager.ToAbsoluteUri("/hubs/logging"))
|
||||
.WithUrl(NavigationManager.ToAbsoluteUri("/hubs/gameserver"))
|
||||
.Build();
|
||||
|
||||
HubConnection.On<string>("Log", (message) =>
|
||||
HubConnection.On<Guid, string>("Log", (serverId, message) =>
|
||||
{
|
||||
Terminal.WriteLine(message);
|
||||
if (serverId == Id)
|
||||
Terminal.WriteLine(message);
|
||||
});
|
||||
|
||||
await HubConnection.StartAsync();
|
||||
|
|
|
@ -144,7 +144,7 @@ app.UseAuthorization();
|
|||
|
||||
app.UseMvcWithDefaultRoute();
|
||||
|
||||
app.MapHub<LoggingHub>("/hubs/logging");
|
||||
app.MapHub<GameServerHub>("/hubs/gameserver");
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
|
|
|
@ -16,13 +16,13 @@
|
|||
<!-- File Target for all log messages with basic details -->
|
||||
<target xsi:type="File" name="MainLogFile" fileName="${basedir}/Logs/log.txt" archiveEvery="Day" />
|
||||
<target xsi:type="File" name="GameServerLogFile" fileName="${basedir}/Logs/GameServers/${event-properties:ServerName}.log" archiveEvery="Day" />
|
||||
<target xsi:type="LoggingHub" name="GameServerHub" hubUrl="http://localhost:1337/hubs/logging" />
|
||||
<target xsi:type="GameServerHub" name="GameServerHub" hubUrl="http://localhost:1337/hubs/gameserver" />
|
||||
</targets>
|
||||
|
||||
<!-- rules to map from logger name to target -->
|
||||
<rules>
|
||||
<!--All logs, including from Microsoft-->
|
||||
<logger name="*" minlevel="Trace" writeTo="MainLogFile,LoggingHub" />
|
||||
<logger name="*" minlevel="Trace" writeTo="MainLogFile" />
|
||||
<logger name="LANCommander.Services.ServerProcessService" minlevel="Info" writeTo="GameServerLogFile,GameServerHub" />
|
||||
<!--Skip non-critical Microsoft logs and so log only own logs (BlackHole) -->
|
||||
<!--<logger name="Microsoft.*" maxlevel="Info" final="true" />
|
||||
|
|
Loading…
Add table
Reference in a new issue