Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/SeqCli/Cli/Commands/Forward/DumpCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using SeqCli.Config;
using SeqCli.Connection;

namespace SeqCli.Cli.Commands.Forward;

[Command("forward", "dump", "Print the complete log buffer contents as JSON",
Example = "seqcli forward dump")]
class DumpCommand : Command
{
public DumpCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
{
}
}
17 changes: 17 additions & 0 deletions src/SeqCli/Cli/Commands/Forward/InstallCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using SeqCli.Config;
using SeqCli.Connection;

namespace SeqCli.Cli.Commands.Forward;

#if WINDOWS

[Command("forward", "install", "Install the Seq Forwarder as a Windows service",
Example = "seqcli forward install")]
class InstallCommand : Command
{
public InstallCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
{
}
}

#endif
17 changes: 17 additions & 0 deletions src/SeqCli/Cli/Commands/Forward/RestartCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using SeqCli.Config;
using SeqCli.Connection;

namespace SeqCli.Cli.Commands.Forward;

#if WINDOWS

[Command("forward", "restart", "Restart the Seq Forwarder Windows service",
Example = "seqcli forward restart")]
class RestartCommand : Command
{
public RestartCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
{
}
}

#endif
23 changes: 23 additions & 0 deletions src/SeqCli/Cli/Commands/Forward/RunCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using SeqCli.Cli.Features;
using SeqCli.Config;
using SeqCli.Connection;

namespace SeqCli.Cli.Commands.Forward;

[Command("forward", "run", "Run the Seq Forwarder server interactively",
Example = "seqcli forward run")]
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<StoragePathFeature>();
_listenUri = Enable<ListenUriFeature>();
}
}
17 changes: 17 additions & 0 deletions src/SeqCli/Cli/Commands/Forward/StartCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using SeqCli.Config;
using SeqCli.Connection;

namespace SeqCli.Cli.Commands.Forward;

#if WINDOWS

[Command("forward", "start", "Start the Seq Forwarder Windows service",
Example = "seqcli forward start")]
class StartCommand : Command
{
public StartCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
{
}
}

#endif
17 changes: 17 additions & 0 deletions src/SeqCli/Cli/Commands/Forward/StatusCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using SeqCli.Config;
using SeqCli.Connection;

namespace SeqCli.Cli.Commands.Forward;

#if WINDOWS

[Command("forward", "status", "Show the status of the Seq Forwarder service",
Example = "seqcli forward status")]
class StatusCommand : Command
{
public StatusCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
{
}
}

#endif
17 changes: 17 additions & 0 deletions src/SeqCli/Cli/Commands/Forward/StopCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using SeqCli.Config;
using SeqCli.Connection;

namespace SeqCli.Cli.Commands.Forward;

#if WINDOWS

[Command("forward", "stop", "Stop the Seq Forwarder service",
Example = "seqcli forward stop")]
class StopCommand : Command
{
public StopCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
{
}
}

#endif
13 changes: 13 additions & 0 deletions src/SeqCli/Cli/Commands/Forward/TruncateCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using SeqCli.Config;
using SeqCli.Connection;

namespace SeqCli.Cli.Commands.Forward;

[Command("forward", "truncate", "Clear the log buffer contents",
Example = "seqcli forward truncate")]
class TruncateCommand : Command
{
public TruncateCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
{
}
}
17 changes: 17 additions & 0 deletions src/SeqCli/Cli/Commands/Forward/UninstallCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using SeqCli.Config;
using SeqCli.Connection;

namespace SeqCli.Cli.Commands.Forward;

#if WINDOWS

[Command("forward", "uninstall", "Uninstall the Windows service",
Example = "seqcli forward uninstall")]
internal class UninstallCommand : Command
{
public UninstallCommand(SeqConnectionFactory connectionFactory, SeqCliConfig config)
{
}
}

#endif
13 changes: 13 additions & 0 deletions src/SeqCli/Cli/Features/ListenUriFeature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace SeqCli.Cli.Features;

class ListenUriFeature : CommandFeature
{
public string? ListenUri { get; private set; }

public override void Enable(OptionSet options)
{
options.Add("l=|listen=",
"Set the listen Uri; http://localhost:15341/ is used by default.",
v => ListenUri = v);
}
}
58 changes: 58 additions & 0 deletions src/SeqCli/Cli/Features/StoragePathFeature.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
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;
}
}
14 changes: 14 additions & 0 deletions src/SeqCli/SeqCli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@
<ToolCommandName>seqcli</ToolCommandName>
<LangVersion>default</LangVersion>
<Nullable>enable</Nullable>
<IsWindows Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Windows)))' == 'true'">true</IsWindows>
<IsLinux Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::Linux)))' == 'true'">true</IsLinux>
<IsOSX Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))' == 'true'">true</IsOSX>
</PropertyGroup>

<PropertyGroup Condition="'$(IsWindows)'=='true'">
<DefineConstants>WINDOWS</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(IsOSX)'=='true'">
<DefineConstants>OSX</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(IsLinux)'=='true'">
<DefineConstants>LINUX</DefineConstants>
</PropertyGroup>

<ItemGroup>
<Content Include="..\..\asset\SeqCli.ico" Link="SeqCli.ico" />
<Content Include="Attribution\*.txt;..\..\LICENSE">
Expand Down