Ejemplo n.º 1
0
        void Init()
        {
            if (Platform.IsMicrosoft)
            {
                HasAdminRights = new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);
            }

            IsWindowsService = Platform.IsMicrosoft && !Environment.UserInteractive;
            if (IsWindowsService)
            {
                // no log console + service run
                if (!HasAdminRights)
                {
                    throw new NotSupportedException("Service requires administration rights!");
                }

                LogSystem = new LogEventLog(EventLog, ServiceName);
            }
            else
            {
                CommandlineArguments = Arguments.FromEnvironment();

                // commandline run or linux daemon ?
                if (!CommandlineArguments.IsOptionPresent("daemon"))
                {
                    // no daemon -> log console
                    LogConsole       = LogConsole.Create();
                    LogConsole.Title = ServiceName + " v" + VersionInfo.InformalVersion;
                    if (CommandlineArguments.IsOptionPresent("debug"))
                    {
                        LogConsole.Level = LogLevel.Debug;
                    }

                    if (CommandlineArguments.IsOptionPresent("verbose"))
                    {
                        LogConsole.Level = LogLevel.Verbose;
                    }

                    if (LogConsole.Level < LogLevel.Information)
                    {
                        LogConsole.ExceptionMode = LogExceptionMode.Full;
                    }
                }

                // on unix do syslog
                LogSystem = LogConsole;
                if (Platform.Type == PlatformType.Linux)
                {
                    LogSystem = LogSyslog.Create();
                }
            }

            if (LogSystem != null)
            {
                LogSystem.ExceptionMode = LogExceptionMode.Full;
            }
            log.LogInfo("Service <cyan>{0}<default> initialized!", ServiceName);
        }
Ejemplo n.º 2
0
 /// <summary>Closes the <see cref="T:Cave.Logging.LogReceiver" />.</summary>
 public override void Close()
 {
     base.Close();
     lock (syncRoot)
     {
         Syslog.Close();
         instance = null;
     }
 }
Ejemplo n.º 3
0
 /// <summary>Creates a new instance.</summary>
 /// <returns>The new syslog instance.</returns>
 /// <exception cref="Exception">Only one instance allowed!.</exception>
 public static LogSyslog Create()
 {
     lock (syncRoot)
     {
         if (instance == null)
         {
             Syslog.Init();
             instance = new LogSyslog();
         }
         else
         {
             throw new Exception("Only one instance allowed!");
         }
         return(instance);
     }
 }