Exemplo n.º 1
0
 public static void SetFunc(LogWriterFunc func)
 {
     if (func == null)
     {
         throw new ArgumentNullException(nameof(func));
     }
     if (isFuncSet)
     {
         throw new InvalidOperationException("Log writer function can only be set once.");
     }
     // If using one of the default functions, pass the unmanged function
     // pointer instead of wrapping the managed version.
     if (func == Default)
     {
         g_log_set_writer_func(g_log_writer_default, IntPtr.Zero, null);
     }
     else if (func == Journald)
     {
         g_log_set_writer_func(g_log_writer_journald, IntPtr.Zero, null);
     }
     else if (func == StandardStreams)
     {
         g_log_set_writer_func(g_log_writer_standard_streams, IntPtr.Zero, null);
     }
     else
     {
         var(func_, userDataFree_, userData_) = UnmanagedLogWriterFuncFactory.CreateNotifyDelegate(func);
         g_log_set_writer_func(func_, userData_, userDataFree_);
     }
     isFuncSet = true;
 }
Exemplo n.º 2
0
 public LinuxServiceLogWriter(LogWriterFunc debugFormat = null, LogWriterFunc infoFormat = null, LogWriterFunc warnFormat = null, LogWriterFunc errorFormat = null, LogWriterFunc fatalFormat = null)
 {
     _debugFormat = debugFormat;
     _infoFormat  = infoFormat;
     _warnFormat  = warnFormat;
     _errorFormat = errorFormat;
     _fatalFormat = fatalFormat;
 }
Exemplo n.º 3
0
 public LinuxServiceLogWriter(LogWriterFunc debugFormat = null, LogWriterFunc infoFormat = null, LogWriterFunc warnFormat = null, LogWriterFunc errorFormat = null, LogWriterFunc fatalFormat = null)
 {
     _debugFormat = debugFormat;
     _infoFormat = infoFormat;
     _warnFormat = warnFormat;
     _errorFormat = errorFormat;
     _fatalFormat = fatalFormat;
 }
Exemplo n.º 4
0
        public static ValueTuple <UnmanagedLogWriterFunc, IntPtr> CreateDelegate(LogWriterFunc func, bool isAsync = false)
        {
            var data = new UnmanagedLogWriterFuncData {
                IsAsync         = isAsync,
                Func            = func,
                UnmanagedFunc   = UnmanagedFunc,
                UnmanagedNotify = null,
            };
            var gcHandle = GCHandle.Alloc(data);

            return(data.UnmanagedFunc, (IntPtr)gcHandle);
        }
Exemplo n.º 5
0
 private static void LogFormat(LogWriterFunc logFunc, string format, params object[] args)
 {
     if (logFunc != null)
     {
         try
         {
             logFunc(format, args);
         }
         catch
         {
         }
     }
 }
Exemplo n.º 6
0
 private static void LogFormat(LogWriterFunc logFunc, string format, params object[] args)
 {
     if (logFunc != null)
     {
         try
         {
             logFunc(format, args);
         }
         catch
         {
         }
     }
 }
Exemplo n.º 7
0
        public static ValueTuple <UnmanagedLogWriterFunc, UnmanagedDestroyNotify, IntPtr> CreateNotifyDelegate(LogWriterFunc func)
        {
            var data = new UnmanagedLogWriterFuncData {
                IsAsync         = false,
                Func            = func,
                UnmanagedFunc   = UnmanagedFunc,
                UnmanagedNotify = UnmanagedNotify,
            };
            var gcHandle = GCHandle.Alloc(data);

            return(data.UnmanagedFunc, data.UnmanagedNotify, (IntPtr)gcHandle);
        }