private static void SetLogHookCallbackImpl(IntPtr ptr, LogLevel level, string message) { GCHandle h = GCHandle.FromIntPtr(ptr); SetLogHookHandler callback = (SetLogHookHandler)h.Target; callback(level, message); }
/// <summary> /// Registers a logging callback function with the minimum level of message to receive /// </summary> /// <param name="minLevel"></param> /// <param name="callback"></param> /// <exception cref="InitializedException"></exception> public void SetLogHook(LogLevel minLevel, SetLogHookHandler callback) { if (!IsInitialized) { throw new InitializedException("The Discord game SDK is not initialized!"); } setLogHook?.Free(); setLogHook = GCHandle.Alloc(callback); Methods.SetLogHook(methodsPtr, minLevel, GCHandle.ToIntPtr(setLogHook.Value), SetLogHookCallbackImpl); }