aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd
diff options
context:
space:
mode:
authorJP Dillingham <jpdillingham@gmail.com>2021-01-16 16:13:08 -0600
committerJP Dillingham <jpdillingham@gmail.com>2021-01-16 16:13:08 -0600
commitd33875ab9061217a6cb148e9f92553516fd3caab (patch)
tree4c86d9eb3d91f670878ceb0065936c3cc453e443 /src/slskd
parent0b7131813818ab5f19904bb1ad0eefc6a2a5fe15 (diff)
downloadslskd-d33875ab9061217a6cb148e9f92553516fd3caab.tar.gz
log diagnostics with serilog
Diffstat (limited to 'src/slskd')
-rw-r--r--src/slskd/Startup.cs29
1 files changed, 16 insertions, 13 deletions
diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs
index 59dead6a..00475b58 100644
--- a/src/slskd/Startup.cs
+++ b/src/slskd/Startup.cs
@@ -27,6 +27,8 @@
using slskd.Security;
using slskd.Trackers;
using Microsoft.Extensions.Logging;
+ using System.Collections.Concurrent;
+ using Serilog;
public class Startup
{
@@ -89,11 +91,15 @@
BasePath ??= "/";
BasePath = BasePath.StartsWith("/") ? BasePath : $"/{BasePath}";
- Console.WriteLine($"Serving static content from {WebRoot}");
- Console.WriteLine($"Using base request path {BasePath}");
+ var logger = Log.ForContext<Startup>();
+
+ logger.Information("Serving static content from {WebRoot}", WebRoot);
+ logger.Information("Using base request path {BasePath}", BasePath);
}
public IConfiguration Configuration { get; }
+ public ILoggerFactory LoggerFactory { get; private set; }
+ public ConcurrentDictionary<string, Microsoft.Extensions.Logging.ILogger> Loggers { get; } = new ConcurrentDictionary<string, Microsoft.Extensions.Logging.ILogger>();
public void ConfigureServices(IServiceCollection services)
{
@@ -180,6 +186,8 @@
IConversationTracker conversationTracker,
IRoomTracker roomTracker)
{
+ LoggerFactory = loggerFactory;
+
if (!env.IsDevelopment())
{
app.UseHsts();
@@ -187,6 +195,9 @@
app.UseCors("AllowAll");
app.UseAuthentication();
+
+ app.UseSerilogRequestLogging();
+
app.UseRouting();
app.UsePathBase(BasePath);
@@ -248,8 +259,6 @@
// begin SoulseekClient implementation
// ---------------------------------------------------------------------------------------------------------------------------------------------
- var logger = loggerFactory.CreateLogger<Startup>();
-
var connectionOptions = new ConnectionOptions(
readBufferSize: ReadBufferSize,
writeBufferSize: WriteBufferSize,
@@ -287,17 +296,11 @@
DiagnosticLevel.Info => LogLevel.Information,
DiagnosticLevel.Warning => LogLevel.Warning,
DiagnosticLevel.None => LogLevel.None,
- _ => LogLevel.None
+ _ => default
};
- if (args.Level == DiagnosticLevel.Debug)
- {
- logger.Log(TranslateLogLevel(args.Level), "[DIAG] {@Message} (source: {@source})", args.Message, e.GetType().Name);
- }
- else
- {
- logger.Log(TranslateLogLevel(args.Level), "[DIAG] {@Message}", args.Message);
- }
+ var logger = Loggers.GetOrAdd(e.GetType().FullName, LoggerFactory.CreateLogger(e.GetType().FullName));
+ logger.Log(TranslateLogLevel(args.Level), "{@Message}", args.Message);
};
// bind transfer events. see TransferStateChangedEventArgs and TransferProgressEventArgs.