// Re-create just in case it was inadvertently deleted. SeqForwarderConfig LoadOrCreateConfig() { if (File.Exists(_storagePath.ConfigFilePath)) { return(SeqForwarderConfig.Read(_storagePath.ConfigFilePath)); } return(InstallCommand.CreateDefaultConfig(_storagePath)); }
protected override int Run(TextWriter cout) { Log.Logger = new LoggerConfiguration() .WriteTo.LiterateConsole() .CreateLogger(); try { if (string.IsNullOrWhiteSpace(_file)) { Log.Fatal("A log file to import must be specified"); return(1); } if (!File.Exists(_file)) { Log.Fatal("The specified import log file does not exist"); return(1); } string serverUrl = null, apiKey = null; if (_serverInformation.IsUrlSpecified) { serverUrl = _serverInformation.Url; apiKey = _serverInformation.ApiKey; } else if (File.Exists(_storagePath.ConfigFilePath)) { var config = SeqForwarderConfig.Read(_storagePath.ConfigFilePath); if (string.IsNullOrEmpty(config.Output.ServerUrl)) { serverUrl = config.Output.ServerUrl; apiKey = _serverInformation.IsApiKeySpecified ? _serverInformation.ApiKey : config.Output.ApiKey; } } if (serverUrl == null) { Log.Fatal("A Seq server URL must be specified or set in the SeqForwarder.json config file"); return(1); } Task.Run(async() => await Run(serverUrl, apiKey, _file, _keyValueProperties.Properties, 256 * 1024, 1024 * 1024)).Wait(); return(0); } catch (Exception ex) { Log.Fatal(ex, "Could not complete import"); return(1); } finally { Log.CloseAndFlush(); } }
protected override int Run(TextWriter cout) { try { var config = SeqForwarderConfig.Read(_storagePath.ConfigFilePath); var buffer = new LogBuffer(_storagePath.BufferPath, config.Storage.BufferSizeBytes); buffer.Truncate(); return(0); } catch (Exception ex) { var logger = new LoggerConfiguration().WriteTo.LiterateConsole().CreateLogger(); logger.Fatal(ex, "Could not truncate log buffer"); return(1); } }
protected override int Run(TextWriter cout) { try { var config = SeqForwarderConfig.Read(_storagePath.ConfigFilePath); var buffer = new LogBuffer(_storagePath.BufferPath, config.Storage.BufferSizeBytes); buffer.Enumerate((k, v) => { var s = Encoding.UTF8.GetString(v); Console.WriteLine(s); }); return(0); } catch (Exception ex) { var logger = new LoggerConfiguration().WriteTo.LiterateConsole().CreateLogger(); logger.Fatal(ex, "Could not dump events"); return(1); } }
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); } }
protected override int Run(TextWriter cout) { try { var config = SeqForwarderConfig.Read(_storagePath.ConfigFilePath); using (var buffer = new ActiveLogBufferMap(_storagePath.BufferPath, config.Storage, config.Output, new InertLogShipperFactory())) { buffer.Load(); buffer.Enumerate((k, v) => { var s = Encoding.UTF8.GetString(v); Console.WriteLine(s); }); } return(0); } catch (Exception ex) { var logger = new LoggerConfiguration().WriteTo.Console().CreateLogger(); logger.Fatal(ex, "Could not dump events"); 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); } 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(); 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(); 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(); }