diff --git a/src/SeqCli/Cli/Commands/ConfigCommand.cs b/src/SeqCli/Cli/Commands/ConfigCommand.cs index 5ec9beec..f991dc44 100644 --- a/src/SeqCli/Cli/Commands/ConfigCommand.cs +++ b/src/SeqCli/Cli/Commands/ConfigCommand.cs @@ -107,7 +107,7 @@ static void Set(SeqCliConfig config, string key, string? value) if (first == null) throw new ArgumentException("The key could not be found; run the command without any arguments to view all keys."); - if (first.PropertyType == typeof(Dictionary)) + if (first.PropertyType == typeof(Dictionary)) throw new NotSupportedException("Use `seqcli profile create` to configure connection profiles."); var second = first.PropertyType.GetTypeInfo().DeclaredProperties diff --git a/src/SeqCli/Cli/Commands/Forward/RunCommand.cs b/src/SeqCli/Cli/Commands/Forward/RunCommand.cs index f2b0ed66..ca1627ed 100644 --- a/src/SeqCli/Cli/Commands/Forward/RunCommand.cs +++ b/src/SeqCli/Cli/Commands/Forward/RunCommand.cs @@ -1,3 +1,4 @@ +using System; using SeqCli.Cli.Features; using SeqCli.Config; using SeqCli.Connection; @@ -11,13 +12,11 @@ class RunCommand : Command #pragma warning disable CS0414 // Field is assigned but its value is never used bool _noLogo; #pragma warning restore CS0414 // Field is assigned but its value is never used - readonly StoragePathFeature _storagePath; readonly ListenUriFeature _listenUri; public RunCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config) { Options.Add("nologo", _ => _noLogo = true); - _storagePath = Enable(); _listenUri = Enable(); } } \ No newline at end of file diff --git a/src/SeqCli/Cli/Commands/Node/ListCommand.cs b/src/SeqCli/Cli/Commands/Node/ListCommand.cs index bf030933..9b24b03c 100644 --- a/src/SeqCli/Cli/Commands/Node/ListCommand.cs +++ b/src/SeqCli/Cli/Commands/Node/ListCommand.cs @@ -32,7 +32,7 @@ class ListCommand : Command string? _name, _id; - public ListCommand(SeqConnectionFactory connectionFactory, SeqCliOutputConfig outputConfig) + public ListCommand(SeqConnectionFactory connectionFactory, OutputConfig outputConfig) { _connectionFactory = connectionFactory ?? throw new ArgumentNullException(nameof(connectionFactory)); diff --git a/src/SeqCli/Cli/Commands/PrintCommand.cs b/src/SeqCli/Cli/Commands/PrintCommand.cs index a5d24dda..2a96e68a 100644 --- a/src/SeqCli/Cli/Commands/PrintCommand.cs +++ b/src/SeqCli/Cli/Commands/PrintCommand.cs @@ -38,7 +38,7 @@ class PrintCommand : Command string? _filter, _template = OutputFormatFeature.DefaultOutputTemplate; bool _noColor, _forceColor; - public PrintCommand(SeqCliOutputConfig outputConfig) + public PrintCommand(OutputConfig outputConfig) { if (outputConfig == null) throw new ArgumentNullException(nameof(outputConfig)); _noColor = outputConfig.DisableColor; diff --git a/src/SeqCli/Cli/Commands/Profile/CreateCommand.cs b/src/SeqCli/Cli/Commands/Profile/CreateCommand.cs index 83d32e21..d6769739 100644 --- a/src/SeqCli/Cli/Commands/Profile/CreateCommand.cs +++ b/src/SeqCli/Cli/Commands/Profile/CreateCommand.cs @@ -49,7 +49,7 @@ int RunSync() try { var config = SeqCliConfig.Read(); - config.Profiles[_name] = new SeqCliConnectionConfig { ServerUrl = _url, ApiKey = _apiKey }; + config.Profiles[_name] = new ConnectionConfig { ServerUrl = _url, ApiKey = _apiKey }; SeqCliConfig.Write(config); return 0; } diff --git a/src/SeqCli/Cli/Features/OutputFormatFeature.cs b/src/SeqCli/Cli/Features/OutputFormatFeature.cs index f64ef386..ac6a237f 100644 --- a/src/SeqCli/Cli/Features/OutputFormatFeature.cs +++ b/src/SeqCli/Cli/Features/OutputFormatFeature.cs @@ -40,7 +40,7 @@ class OutputFormatFeature : CommandFeature bool _json, _noColor, _forceColor; - public OutputFormatFeature(SeqCliOutputConfig outputConfig) + public OutputFormatFeature(OutputConfig outputConfig) { _noColor = outputConfig.DisableColor; _forceColor = outputConfig.ForceColor; diff --git a/src/SeqCli/Cli/Features/StoragePathFeature.cs b/src/SeqCli/Cli/Features/StoragePathFeature.cs deleted file mode 100644 index ce363a44..00000000 --- a/src/SeqCli/Cli/Features/StoragePathFeature.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.IO; - -namespace SeqCli.Cli.Features; - -class StoragePathFeature : CommandFeature -{ - string? _storageRoot; - - public string StorageRootPath - { - get - { - if (!string.IsNullOrWhiteSpace(_storageRoot)) - return _storageRoot; - - return TryQueryInstalledStorageRoot() ?? GetDefaultStorageRoot(); - } - } - - public string ConfigFilePath => Path.Combine(StorageRootPath, "SeqForwarder.json"); - - public string BufferPath => Path.Combine(StorageRootPath, "Buffer"); - - public override void Enable(OptionSet options) - { - options.Add("s=|storage=", - "Set the folder where data will be stored; " + - "" + GetDefaultStorageRoot() + " is used by default.", - v => _storageRoot = Path.GetFullPath(v)); - } - - static string GetDefaultStorageRoot() - { - return Path.GetFullPath(Path.Combine( -#if WINDOWS - // Common, here, because the service may run as Local Service, which has no obvious home - // directory. - Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), -#else - // Specific to and writable by the current user. - Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), -#endif - "Seq", - "Forwarder")); - } - - static string? TryQueryInstalledStorageRoot() - { -#if WINDOWS - // if (Seq.Forwarder.Util.ServiceConfiguration.GetServiceStoragePath( - // Seq.Forwarder.ServiceProcess.SeqForwarderWindowsService.WindowsServiceName, out var storage)) - // return storage; -#endif - - return null; - } -} \ No newline at end of file diff --git a/src/SeqCli/Config/SeqCliConnectionConfig.cs b/src/SeqCli/Config/ConnectionConfig.cs similarity index 98% rename from src/SeqCli/Config/SeqCliConnectionConfig.cs rename to src/SeqCli/Config/ConnectionConfig.cs index 072d733e..57b6fd50 100644 --- a/src/SeqCli/Config/SeqCliConnectionConfig.cs +++ b/src/SeqCli/Config/ConnectionConfig.cs @@ -18,7 +18,7 @@ namespace SeqCli.Config; -class SeqCliConnectionConfig +class ConnectionConfig { const string ProtectedDataPrefix = "pd."; diff --git a/src/SeqCli/Config/Forwarder/ForwarderApiConfig.cs b/src/SeqCli/Config/Forwarder/ForwarderApiConfig.cs new file mode 100644 index 00000000..321e8017 --- /dev/null +++ b/src/SeqCli/Config/Forwarder/ForwarderApiConfig.cs @@ -0,0 +1,6 @@ +namespace SeqCli.Config; + +class ForwarderApiConfig +{ + public string ListenUri { get; set; } = "http://localhost:15341"; +} \ No newline at end of file diff --git a/src/SeqCli/Config/Forwarder/ForwarderConfig.cs b/src/SeqCli/Config/Forwarder/ForwarderConfig.cs new file mode 100644 index 00000000..621072cc --- /dev/null +++ b/src/SeqCli/Config/Forwarder/ForwarderConfig.cs @@ -0,0 +1,12 @@ +namespace SeqCli.Config; + +class ForwarderConfig +{ + public uint? PooledConnectionLifetimeMilliseconds { get; set; } = null; + public ulong EventBodyLimitBytes { get; set; } = 256 * 1024; + public ulong PayloadLimitBytes { get; set; } = 10 * 1024 * 1024; + + public ForwarderStorageConfig Storage { get; set; } = new(); + public ForwarderDiagnosticConfig Diagnostics { get; set; } = new(); + public ForwarderApiConfig Api { get; set; } = new(); +} \ No newline at end of file diff --git a/src/SeqCli/Config/Forwarder/ForwarderDiagnosticConfig.cs b/src/SeqCli/Config/Forwarder/ForwarderDiagnosticConfig.cs new file mode 100644 index 00000000..8366a6e4 --- /dev/null +++ b/src/SeqCli/Config/Forwarder/ForwarderDiagnosticConfig.cs @@ -0,0 +1,29 @@ +using System; +using System.IO; +using Serilog.Events; + +namespace SeqCli.Config; + +public class ForwarderDiagnosticConfig +{ + public string InternalLogPath { get; set; } = GetDefaultInternalLogPath(); + public LogEventLevel InternalLoggingLevel { get; set; } = LogEventLevel.Information; + public string? InternalLogServerUri { get; set; } + public string? InternalLogServerApiKey { get; set; } + public bool IngestionLogShowDetail { get; set; } + + public static string GetDefaultInternalLogPath() + { + return Path.Combine( +#if WINDOWS + // Common, here, because the service may run as Local Service, which has no obvious home + // directory. + Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), +#else + // Specific to and writable by the current user. + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), +#endif + "Seq", + "Logs"); + } +} \ No newline at end of file diff --git a/src/SeqCli/Config/Forwarder/ForwarderStorageConfig.cs b/src/SeqCli/Config/Forwarder/ForwarderStorageConfig.cs new file mode 100644 index 00000000..f2143eaa --- /dev/null +++ b/src/SeqCli/Config/Forwarder/ForwarderStorageConfig.cs @@ -0,0 +1,6 @@ +namespace SeqCli.Config; + +public class ForwarderStorageConfig +{ + public int BufferSizeBytes { get; set; } = 67_108_864; +} \ No newline at end of file diff --git a/src/SeqCli/Config/SeqCliOutputConfig.cs b/src/SeqCli/Config/OutputConfig.cs similarity index 96% rename from src/SeqCli/Config/SeqCliOutputConfig.cs rename to src/SeqCli/Config/OutputConfig.cs index 62b3a6f2..8727c2b3 100644 --- a/src/SeqCli/Config/SeqCliOutputConfig.cs +++ b/src/SeqCli/Config/OutputConfig.cs @@ -14,7 +14,7 @@ namespace SeqCli.Config; -class SeqCliOutputConfig +public class OutputConfig { public bool DisableColor { get; set; } public bool ForceColor { get; set; } diff --git a/src/SeqCli/Config/SeqCliConfig.cs b/src/SeqCli/Config/SeqCliConfig.cs index dd3b51ca..307f14b8 100644 --- a/src/SeqCli/Config/SeqCliConfig.cs +++ b/src/SeqCli/Config/SeqCliConfig.cs @@ -51,8 +51,10 @@ public static void Write(SeqCliConfig data) File.WriteAllText(DefaultConfigFilename, content); } - public SeqCliConnectionConfig Connection { get; set; } = new SeqCliConnectionConfig(); - public SeqCliOutputConfig Output { get; set; } = new SeqCliOutputConfig(); - public Dictionary Profiles { get; } = - new Dictionary(StringComparer.OrdinalIgnoreCase); + public ConnectionConfig Connection { get; set; } = new ConnectionConfig(); + public OutputConfig Output { get; set; } = new(); + public ForwarderConfig Forwarder { get; set; } = new(); + + public Dictionary Profiles { get; } = + new Dictionary(StringComparer.OrdinalIgnoreCase); } \ No newline at end of file