From 8790b1a3bfd5e9c2badfdf7388d84277e80125af Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Wed, 9 Aug 2023 22:23:14 +0200 Subject: [PATCH] feat: add file logging --- Server/AuthSession.cs | 2 +- Server/Program.cs | 4 ++++ Server/Server.csproj | 5 +++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Server/AuthSession.cs b/Server/AuthSession.cs index c2727af..ad1c06f 100644 --- a/Server/AuthSession.cs +++ b/Server/AuthSession.cs @@ -189,7 +189,7 @@ public abstract class AuthSession : TcpSession buffer[3], Id, this); Parallel.Invoke(() => _mediator.Send(rawPacket)); - _logger.LogInformation("Connection from: {@RemoteEndpoint}", Socket.RemoteEndPoint); + _logger.LogInformation("Connection from: {@RemoteEndpoint}", Socket.RemoteEndPoint?.ToString()); base.OnReceived(decryptedBuffer.ToArray(), offset, decryptedBuffer.Length); } catch (CryptographicException ex) diff --git a/Server/Program.cs b/Server/Program.cs index b42a324..c529e07 100644 --- a/Server/Program.cs +++ b/Server/Program.cs @@ -1,6 +1,7 @@ using System.Net; using System.Reflection; using MassTransit; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; @@ -9,6 +10,9 @@ using Server; Console.WriteLine(BitConverter.IsLittleEndian); var builder = Host.CreateApplicationBuilder(); +builder.Configuration.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); +builder.Logging.AddFile("Logs/Server-{Date}.log", LogLevel.Trace); +builder.Logging.AddFile("Logs/Server-{Date}.json.log", isJson: true, minimumLevel: LogLevel.Trace); builder.Services.AddLogging(); builder.Services.AddSingleton(); builder.Services.AddHostedService(provider => diff --git a/Server/Server.csproj b/Server/Server.csproj index ab4a803..b5f6fc1 100644 --- a/Server/Server.csproj +++ b/Server/Server.csproj @@ -23,11 +23,16 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive + + + + +