improve logging
This commit is contained in:
@@ -132,7 +132,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("Error at getting context: ", ex.ToString());
|
Log.Error("Error retriving context", ex);
|
||||||
context = null;
|
context = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,6 +145,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Check context
|
// Check context
|
||||||
|
Log.Info("Request retrived for " + context.Request.RawUrl);
|
||||||
OnCheckContext?.Invoke(this, new(context));
|
OnCheckContext?.Invoke(this, new(context));
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -152,7 +153,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.ErrorFormat("Error at checking context: ", ex.ToString());
|
Log.Error("Error checking context", ex);
|
||||||
if (DebugMode)
|
if (DebugMode)
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
@@ -168,11 +169,11 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
|
|
||||||
protected virtual void CheckContext(HttpListenerContext context)
|
protected virtual void CheckContext(HttpListenerContext context)
|
||||||
{
|
{
|
||||||
Log.Info("Start handling request");
|
Log.Debug("Start handling request");
|
||||||
|
|
||||||
void close()
|
void close()
|
||||||
{
|
{
|
||||||
Log.Info("End handling request");
|
Log.Debug("End handling request");
|
||||||
context.Response.OutputStream.Close();
|
context.Response.OutputStream.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +183,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
var query = context.Request.Url?.Query;
|
var query = context.Request.Url?.Query;
|
||||||
if (string.IsNullOrWhiteSpace(path))
|
if (string.IsNullOrWhiteSpace(path))
|
||||||
{
|
{
|
||||||
Log.Info("Request has no path");
|
Log.Warn("Request has no path");
|
||||||
close();
|
close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -191,7 +192,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
Log.Debug("Find handler");
|
Log.Debug("Find handler");
|
||||||
if (!TryGetHandler(path, query, context.Request.HttpMethod, out var 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();
|
close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -246,7 +247,7 @@ public class ApiServer(string apiUrl) : IApiServer
|
|||||||
Log.Debug("Create response");
|
Log.Debug("Create response");
|
||||||
if (result.ResultJson is not null)
|
if (result.ResultJson is not null)
|
||||||
{
|
{
|
||||||
Log.Info("Sending response");
|
Log.Info("Sending response for " + context.Request.RawUrl);
|
||||||
context.Response.ContentType = "application/json";
|
context.Response.ContentType = "application/json";
|
||||||
using StreamWriter output = new(context.Response.OutputStream);
|
using StreamWriter output = new(context.Response.OutputStream);
|
||||||
output.Write(result.ResultJson);
|
output.Write(result.ResultJson);
|
||||||
|
|||||||
Reference in New Issue
Block a user