/// <summary> /// Begins the log. /// </summary> /// <param name="logger">The logger.</param> /// <param name="appPaths">The app paths.</param> private static void BeginLog(ILogger logger, IApplicationPaths appPaths) { logger.Info("Media Browser Server started"); ApplicationHost.LogEnvironmentInfo(logger, appPaths); }
/// <summary> /// Defines the entry point of the application. /// </summary> public static void Main() { var options = new StartupOptions(); _isRunningAsService = options.ContainsOption("-service"); var currentProcess = Process.GetCurrentProcess(); var applicationPath = currentProcess.MainModule.FileName; var appPaths = CreateApplicationPaths(applicationPath, _isRunningAsService); var logManager = new NlogManager(appPaths.LogDirectoryPath, "server"); logManager.ReloadLogger(LogSeverity.Debug); logManager.AddConsoleOutput(); var logger = _logger = logManager.GetLogger("Main"); ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); // Install directly if (options.ContainsOption("-installservice")) { logger.Info("Performing service installation"); InstallService(applicationPath, logger); return; } // Restart with admin rights, then install if (options.ContainsOption("-installserviceasadmin")) { logger.Info("Performing service installation"); RunServiceInstallation(applicationPath); return; } // Uninstall directly if (options.ContainsOption("-uninstallservice")) { logger.Info("Performing service uninstallation"); UninstallService(applicationPath, logger); return; } // Restart with admin rights, then uninstall if (options.ContainsOption("-uninstallserviceasadmin")) { logger.Info("Performing service uninstallation"); RunServiceUninstallation(applicationPath); return; } AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; RunServiceInstallationIfNeeded(applicationPath); if (IsAlreadyRunning(applicationPath, currentProcess)) { logger.Info("Shutting down because another instance of Media Browser Server is already running."); return; } if (PerformUpdateIfNeeded(appPaths, logger)) { logger.Info("Exiting to perform application update."); return; } try { RunApplication(appPaths, logManager, _isRunningAsService, options); } finally { OnServiceShutdown(); } }
public static void Main() { var options = new StartupOptions(Environment.GetCommandLineArgs()); IsRunningAsService = options.ContainsOption("-service"); if (IsRunningAsService) { //_canRestartService = CanRestartWindowsService(); } var currentProcess = Process.GetCurrentProcess(); ApplicationPath = currentProcess.MainModule.FileName; var architecturePath = Path.Combine(Path.GetDirectoryName(ApplicationPath), Environment.Is64BitProcess ? "x64" : "x86"); var success = SetDllDirectory(architecturePath); SQLitePCL.raw.SetProvider(new SQLitePCL.SQLite3Provider_sqlite3()); var appPaths = CreateApplicationPaths(ApplicationPath, IsRunningAsService); var logManager = new SimpleLogManager(appPaths.LogDirectoryPath, "server"); logManager.ReloadLogger(LogSeverity.Debug); logManager.AddConsoleOutput(); var logger = _logger = logManager.GetLogger("Main"); ApplicationHost.LogEnvironmentInfo(logger, appPaths, true); // Install directly if (options.ContainsOption("-installservice")) { logger.Info("Performing service installation"); InstallService(ApplicationPath, logger); return; } // Restart with admin rights, then install if (options.ContainsOption("-installserviceasadmin")) { logger.Info("Performing service installation"); RunServiceInstallation(ApplicationPath); return; } // Uninstall directly if (options.ContainsOption("-uninstallservice")) { logger.Info("Performing service uninstallation"); UninstallService(ApplicationPath, logger); return; } // Restart with admin rights, then uninstall if (options.ContainsOption("-uninstallserviceasadmin")) { logger.Info("Performing service uninstallation"); RunServiceUninstallation(ApplicationPath); return; } AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; RunServiceInstallationIfNeeded(ApplicationPath); if (IsAlreadyRunning(ApplicationPath, currentProcess)) { logger.Info("Shutting down because another instance of Emby Server is already running."); return; } if (PerformUpdateIfNeeded(appPaths, logger)) { logger.Info("Exiting to perform application update."); return; } try { RunApplication(appPaths, logManager, IsRunningAsService, options); } finally { OnServiceShutdown(); } }