mirror of
https://github.com/EpinelPS/EpinelPS.git
synced 2025-12-13 15:34:36 +01:00
reflection-based field logger for req/res msgs
This commit is contained in:
30
EpinelPS/Utils/LogUtils.cs
Normal file
30
EpinelPS/Utils/LogUtils.cs
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
using Google.Protobuf;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
|
namespace EpinelPS.Utils
|
||||||
|
{
|
||||||
|
public static class LogUtils
|
||||||
|
{
|
||||||
|
public static void LogMessageFields(IMessage message)
|
||||||
|
{
|
||||||
|
Type type = message.GetType();
|
||||||
|
FieldInfo[] fields = type.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
|
||||||
|
Console.WriteLine(type.Name + ":");
|
||||||
|
|
||||||
|
foreach (FieldInfo field in fields)
|
||||||
|
{
|
||||||
|
if (field.Name.ToLower().Contains("unknown"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
object? value = field.GetValue(message);
|
||||||
|
|
||||||
|
Console.WriteLine($"\t{field.Name}: {value}");
|
||||||
|
}
|
||||||
|
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user