/// <summary> /// Configures logging to a user-defined function. /// /// This function can be used to get notified whenever the Yogi library itself /// or the user produces log messages. These messages can then be processed /// further in user code. /// </summary> /// <param name="verbosity">Maximum verbosity of messages to log.</param> /// <param name="fn">Callback function.</param> public static void ConfigureHookLogging(Verbosity verbosity, LogToHookFnDelegate fn) { lock (logToHookFnLock) { YogiCore.ConfigureHookLoggingFnDelegate wrapper; if (fn == null) { wrapper = null; } else { wrapper = (severity, timestamp, tid, file, line, comp, msg, userarg) => { var ts = Timestamp.FromDurationSinceEpoch(Duration.FromNanoseconds(timestamp)); fn((Verbosity)severity, ts, tid, file, line, comp, msg); }; } int res = YogiCore.YOGI_ConfigureHookLogging((int)verbosity, wrapper, IntPtr.Zero); logToHookFn = null; CheckErrorCode(res); logToHookFn = wrapper; // Make sure it does not get garbage-collected } }
/// <summary> /// Configures logging to a user-defined function. /// /// This function can be used to get notified whenever the Yogi library itself /// or the user produces log messages. These messages can then be processed /// further in user code. /// </summary> /// <param name="verbosity">Maximum verbosity of messages to log.</param> /// <param name="fn">Callback function.</param> public static void SetupHookLogging(Verbosity verbosity, [Optional] LogToHookFnDelegate fn) { lock (logToHookFnLock) { Api.LogToHookFnDelegate wrapper = (severity, timestamp, tid, file, line, comp, msg, userarg) => { var ts = Timestamp.FromDurationSinceEpoch(Duration.FromNanoseconds(timestamp)); fn(severity, ts, tid, file, line, comp, msg); }; int res = Api.YOGI_ConfigureHookLogging((int)verbosity, wrapper, IntPtr.Zero); logToHookFn = null; CheckErrorCode(res); logToHookFn = wrapper; // Make sure it does not get GC'd } }