|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- using System;
- using System.Collections.Generic;
- using System.Runtime.CompilerServices;
- using System.Diagnostics;
-
- namespace CLre_server.API.Utility
- {
- /// <summary>
- /// Utility class to access Cardlife's built-in logging capabilities.
- /// The log is saved to outputLog#.Log
- /// </summary>
- public static class Logging
- {
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Log(string msg)
- {
- Svelto.Console.Log(msg);
- }
-
- /// <summary>
- /// Write a regular message to Cardlife's log
- /// </summary>
- /// <param name="obj">The object to log</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void Log(object obj)
- {
- Svelto.Console.Log(obj.ToString());
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogError(string msg, Dictionary<string, string> extraData = null)
- {
- Svelto.Console.LogError(msg, extraData);
- }
-
- /// <summary>
- /// Write an error message to Cardlife's log
- /// </summary>
- /// <param name="obj">The object to log</param>
- /// <param name="extraData">The extra data to pass to the ILogger</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogError(object obj, Dictionary<string, string> extraData = null)
- {
- Svelto.Console.LogError(obj.ToString(), extraData);
- }
-
- /// <summary>
- /// Write an exception to Cardlife's log and to the screen and exit game
- /// </summary>
- /// <param name="e">The exception to log</param>
- /// <param name="extraData">The extra data to pass to the ILogger.
- /// This is automatically populated with "OuterException#" and "OuterStacktrace#" entries</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogException(Exception e, string msg = null, Dictionary<string, string> extraData = null)
- {
- Svelto.Console.LogException(msg, e, extraData);
- }
-
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogWarning(string msg)
- {
- Svelto.Console.LogWarning(msg);
- }
-
- /// <summary>
- /// Write a warning message to Cardlife's log
- /// </summary>
- /// <param name="obj">The object to log</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void LogWarning(object obj)
- {
- Svelto.Console.LogWarning(obj.ToString());
- }
-
- // descriptive logging
-
- /// <summary>
- /// Write a descriptive message to Cardlife's log including the calling method's name
- /// </summary>
- /// <param name="obj">The object to log</param>
- [MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void MetaLog(object obj)
- {
- var method = (new StackTrace()).GetFrame(1).GetMethod();
- Log($"[{method.DeclaringType.FullName}.{method.Name}] {obj.ToString()}");
- }
- }
- }
|