public static SeqForwarderConfig CreateDefaultConfig(StoragePathFeature storagePath) { if (!Directory.Exists(storagePath.StorageRootPath)) { Directory.CreateDirectory(storagePath.StorageRootPath); } var config = new SeqForwarderConfig { Output = { ServerUrl = "http://localhost:5341", ApiKey = null, EventBodyLimitBytes = 256 * 1024, RawPayloadLimitBytes = 10 * 1024 * 1024 }, Diagnostics = { InternalLoggingLevel = LogEventLevel.Information, InternalLogPath = GetDefaultInternalLogPath() }, Storage = { BufferSizeBytes = 64 * 1024 * 1024 } }; SeqForwarderConfig.Write(storagePath.ConfigFilePath, config); return(config); }
public static SeqForwarderConfig CreateDefaultConfig(StoragePathFeature storagePath) { if (!Directory.Exists(storagePath.StorageRootPath)) { Directory.CreateDirectory(storagePath.StorageRootPath); } var config = new SeqForwarderConfig(); SeqForwarderConfig.Write(storagePath.ConfigFilePath, config); return(config); }
protected override int Run(TextWriter cout) { try { var config = SeqForwarderConfig.Read(_storagePath.ConfigFilePath); if (_key != null) { if (_clear) { Clear(config, _key); SeqForwarderConfig.Write(_storagePath.ConfigFilePath, config); } else if (_value != null) { Set(config, _key, _value); SeqForwarderConfig.Write(_storagePath.ConfigFilePath, config); } else { Print(cout, config, _key); } } else { List(cout, config); } return(0); } catch (Exception ex) { var logger = new LoggerConfiguration().WriteTo.Console().CreateLogger(); logger.Fatal(ex, "Could not update config"); return(1); } }
void Install(TextWriter cout) { cout.WriteLine("Installing service..."); if (PathIsNetworkPath(_storagePath.StorageRootPath)) { throw new ArgumentException("Seq Forwarder requires a local (or SAN) storage location; network shares are not supported."); } SeqForwarderConfig config; if (File.Exists(_storagePath.ConfigFilePath)) { cout.WriteLine($"Using the configuration found in {_storagePath.ConfigFilePath}..."); config = SeqForwarderConfig.Read(_storagePath.ConfigFilePath); } else { cout.WriteLine($"Creating a new configuration file in {_storagePath.ConfigFilePath}..."); config = CreateDefaultConfig(_storagePath); } if (!string.IsNullOrEmpty(_listenUri.ListenUri)) { config.Api.ListenUri = _listenUri.ListenUri; SeqForwarderConfig.Write(_storagePath.ConfigFilePath, config); } var args = new List <string> { "/LogFile=\"\"", "/ShowCallStack", "/storage=\"" + _storagePath.StorageRootPath + "\"", GetType().Assembly.Location }; if (_serviceCredentials.IsUsernameSpecified) { if (!_serviceCredentials.IsPasswordSpecified) { throw new ArgumentException("If a service user account is specified, a password for the account must also be specified."); } // https://technet.microsoft.com/en-us/library/cc794944(v=ws.10).aspx cout.WriteLine($"Ensuring {_serviceCredentials.Username} is granted 'Log on as a Service' rights..."); AccountRightsHelper.EnsureServiceLogOnRights(_serviceCredentials.Username); cout.WriteLine($"Granting {_serviceCredentials.Username} rights to {_storagePath.StorageRootPath}..."); GiveFullControl(_storagePath.StorageRootPath, _serviceCredentials.Username); cout.WriteLine($"Granting {_serviceCredentials.Username} rights to {config.Diagnostics.InternalLogPath}..."); GiveFullControl(config.Diagnostics.InternalLogPath, _serviceCredentials.Username); var listenUri = MakeListenUriReservationPattern(config.Api.ListenUri); cout.WriteLine($"Adding URL reservation at {listenUri} for {_serviceCredentials.Username} (may request UAC elevation)..."); NetSh.AddUrlAcl(listenUri, _serviceCredentials.Username); args.Insert(0, "/username=\"" + _serviceCredentials.Username + "\""); args.Insert(0, "/password=\"" + _serviceCredentials.Password + "\""); } else { cout.WriteLine($"Granting the NT AUTHORITY\\LocalService account rights to {_storagePath.StorageRootPath}..."); GiveFullControl(_storagePath.StorageRootPath, "NT AUTHORITY\\LocalService"); cout.WriteLine($"Granting NT AUTHORITY\\LocalService account rights to {config.Diagnostics.InternalLogPath}..."); GiveFullControl(config.Diagnostics.InternalLogPath, "NT AUTHORITY\\LocalService"); var listenUri = MakeListenUriReservationPattern(config.Api.ListenUri); cout.WriteLine($"Adding URL reservation at {listenUri} for the Local Service account (may request UAC elevation)..."); NetSh.AddUrlAcl(listenUri, "NT AUTHORITY\\LocalService"); } ManagedInstallerClass.InstallHelper(args.ToArray()); Console.ForegroundColor = ConsoleColor.Green; cout.WriteLine("Service installed successfully."); Console.ResetColor(); }