Exemplo n.º 1
0
        public static uint SetHandler(string logDomain, LogLevelFlags logLevels, LogFunc logFunc)
        {
            if (logFunc == null)
            {
                throw new ArgumentNullException(nameof(logFunc));
            }
            var logDomain_ = GMarshal.StringToUtf8Ptr(logDomain);

            var(logFunc_, destroy_, userData_) = UnmanagedLogFuncFactory.CreateNotifyDelegate(logFunc);
            var ret = g_log_set_handler_full(logDomain_, logLevels, logFunc_, userData_, destroy_);

            GMarshal.Free(logDomain_);
            return(ret);
        }
Exemplo n.º 2
0
        public static void SetDefaultHandler(LogFunc logFunc)
        {
            if (logFunc == null)
            {
                throw new ArgumentNullException(nameof(logFunc));
            }
            var oldHandler = defaultHandler;

            if (logFunc == DefaultHandler)
            {
                g_log_set_default_handler(g_log_default_handler, IntPtr.Zero);
                defaultHandler = default(GCHandle);
            }
            else
            {
                var(logFunc_, userData_) = UnmanagedLogFuncFactory.CreateDelegate(logFunc);
                g_log_set_default_handler(logFunc_, userData_);
                defaultHandler = (GCHandle)userData_;
            }
            if (oldHandler.IsAllocated)
            {
                oldHandler.Free();
            }
        }