move marehub to strong api usage (#14)

* move marehub to strong api usage

* fix merge issues

* latest api

* further optimizations
This commit is contained in:
rootdarkarchon
2022-10-08 14:33:25 +02:00
committed by GitHub
parent a8f97aee23
commit 777a764ef1
14 changed files with 362 additions and 256 deletions

View File

@@ -1,5 +1,6 @@
using MareSynchronosServer.Hubs;
using Microsoft.Extensions.Logging;
using System.Runtime.CompilerServices;
namespace MareSynchronosServer.Utils;
@@ -13,16 +14,20 @@ public class MareHubLogger
_hub = hub;
_logger = logger;
}
public void LogCallInfo(string methodName, params object[] args)
public static object[] Args(params object[] args)
{
string formattedArgs = args.Length != 0 ? "|" + string.Join(":", args) : string.Empty;
return args;
}
public void LogCallInfo(object[] args = null, [CallerMemberName] string methodName = "")
{
string formattedArgs = args != null && args.Length != 0 ? "|" + string.Join(":", args) : string.Empty;
_logger.LogInformation("{uid}:{method}{args}", _hub.AuthenticatedUserId, methodName, formattedArgs);
}
public void LogCallWarning(string methodName, params object[] args)
public void LogCallWarning(object[] args = null, [CallerMemberName] string methodName = "")
{
string formattedArgs = args.Length != 0 ? "|" + string.Join(":", args) : string.Empty;
string formattedArgs = args != null && args.Length != 0 ? "|" + string.Join(":", args) : string.Empty;
_logger.LogWarning("{uid}:{method}{args}", _hub.AuthenticatedUserId, methodName, formattedArgs);
}
}