From cdd79151423cd7e3bd6b9200c9e813cb2dc59c8b Mon Sep 17 00:00:00 2001 From: Pilzinsel64 Date: Mon, 9 Dec 2024 06:29:05 +0100 Subject: [PATCH] improve logging --- Pilz.Net/Api/ApiServer.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Pilz.Net/Api/ApiServer.cs b/Pilz.Net/Api/ApiServer.cs index 3b68918..5ef22a4 100644 --- a/Pilz.Net/Api/ApiServer.cs +++ b/Pilz.Net/Api/ApiServer.cs @@ -132,7 +132,7 @@ public class ApiServer(string apiUrl) : IApiServer } catch (Exception ex) { - Log.ErrorFormat("Error at getting context: ", ex.ToString()); + Log.Error("Error retriving context", ex); context = null; } @@ -145,6 +145,7 @@ public class ApiServer(string apiUrl) : IApiServer return; // Check context + Log.Info("Request retrived for " + context.Request.RawUrl); OnCheckContext?.Invoke(this, new(context)); try { @@ -152,7 +153,7 @@ public class ApiServer(string apiUrl) : IApiServer } catch (Exception ex) { - Log.ErrorFormat("Error at checking context: ", ex.ToString()); + Log.Error("Error checking context", ex); if (DebugMode) throw; } @@ -168,11 +169,11 @@ public class ApiServer(string apiUrl) : IApiServer protected virtual void CheckContext(HttpListenerContext context) { - Log.Info("Start handling request"); + Log.Debug("Start handling request"); void close() { - Log.Info("End handling request"); + Log.Debug("End handling request"); context.Response.OutputStream.Close(); } @@ -182,7 +183,7 @@ public class ApiServer(string apiUrl) : IApiServer var query = context.Request.Url?.Query; if (string.IsNullOrWhiteSpace(path)) { - Log.Info("Request has no path"); + Log.Warn("Request has no path"); close(); return; } @@ -191,7 +192,7 @@ public class ApiServer(string apiUrl) : IApiServer Log.Debug("Find handler"); if (!TryGetHandler(path, query, context.Request.HttpMethod, out var handler)) { - Log.Info("Request handler couldn't be found"); + Log.Warn("Request handler couldn't be found"); close(); return; } @@ -246,7 +247,7 @@ public class ApiServer(string apiUrl) : IApiServer Log.Debug("Create response"); if (result.ResultJson is not null) { - Log.Info("Sending response"); + Log.Info("Sending response for " + context.Request.RawUrl); context.Response.ContentType = "application/json"; using StreamWriter output = new(context.Response.OutputStream); output.Write(result.ResultJson);