From 48bceda3f39a00a4f355d410e4f3472a537b43b7 Mon Sep 17 00:00:00 2001 From: Nicholas Blumhardt Date: Fri, 7 Jul 2023 10:05:08 +1000 Subject: [PATCH] Update for Seq 2023.3 --- example/SeqEnableAAD/Program.cs | 121 +++++++-------- example/SeqEnableAAD/SeqEnableAAD.csproj | 7 +- example/SeqQuery/Program.cs | 78 ++++------ example/SeqQuery/SeqQuery.csproj | 7 +- example/SeqTail/Program.cs | 102 ++++++------- .../SeqTail/Properties/launchSettings.json | 8 - example/SeqTail/SeqTail.csproj | 11 +- example/SignalCopy/Program.cs | 141 ++++++++---------- .../SignalCopy/Properties/launchSettings.json | 8 - example/SignalCopy/SignalCopy.csproj | 5 +- src/Seq.Api/Seq.Api.csproj | 2 +- test/Seq.Api.Tests/Seq.Api.Tests.csproj | 9 +- 12 files changed, 221 insertions(+), 278 deletions(-) delete mode 100644 example/SeqTail/Properties/launchSettings.json delete mode 100644 example/SignalCopy/Properties/launchSettings.json diff --git a/example/SeqEnableAAD/Program.cs b/example/SeqEnableAAD/Program.cs index 259a6e1..cb58208 100644 --- a/example/SeqEnableAAD/Program.cs +++ b/example/SeqEnableAAD/Program.cs @@ -4,11 +4,7 @@ using Seq.Api; using Seq.Api.Model.Settings; -namespace SeqEnableAAD -{ - class Program - { - const string Usage = @"seq-enable-aad: enable authentication on your Seq server (for initial setup of a new Seq server only). +const string usage = @"seq-enable-aad: enable authentication on your Seq server (for initial setup of a new Seq server only). Usage: seq-enable-aad.exe --uname= --tenantid= --clientid= --clientkey= [--authority=] @@ -21,71 +17,64 @@ class Program --clientid= Client ID. --clientkey= Client key. --authority= Authority (optional, defaults to 'login.windows.net'). - "; - static void Main(string[] args) - { - Task.Run(async () => - { - try - { - var arguments = new Docopt().Apply(Usage, args, version: "Seq Enable AAD 0.1", exit: true); +"; - var server = arguments[""].ToString(); - var username = Normalize(arguments["--uname"]); - var tenantId = Normalize(arguments["--tenantid"]); - var clientId = Normalize(arguments["--clientid"]); - var clientKey = Normalize(arguments["--clientkey"]); - var authority = Normalize(arguments["--authority"]); +try +{ + var arguments = new Docopt().Apply(usage, args, version: "Seq Enable AAD 0.1", exit: true)!; - await Run(server, username, tenantId, clientId, clientKey, authority); - } - catch (Exception ex) - { - Console.ForegroundColor = ConsoleColor.White; - Console.BackgroundColor = ConsoleColor.Red; - Console.WriteLine("seq-enable-aad: {0}", ex); - Console.ResetColor(); - Environment.Exit(-1); - } - }).Wait(); - } - - static string Normalize(ValueObject v) - { - if (v == null) return null; - var s = v.ToString(); - return string.IsNullOrWhiteSpace(s) ? null : s; - } + var server = arguments[""].ToString(); + var username = Normalize(arguments["--uname"]); + var tenantId = Normalize(arguments["--tenantid"]); + var clientId = Normalize(arguments["--clientid"]); + var clientKey = Normalize(arguments["--clientkey"]); + var authority = Normalize(arguments["--authority"]); + + await Run(server, username, tenantId, clientId, clientKey, authority); +} +catch (Exception ex) +{ + Console.ForegroundColor = ConsoleColor.White; + Console.BackgroundColor = ConsoleColor.Red; + Console.WriteLine("seq-enable-aad: {0}", ex); + Console.ResetColor(); + Environment.Exit(-1); +} - static async Task Run(string server, string username, string tenantId, string clientId, string clientKey, string authority="login.windows.net") - { - var connection = new SeqConnection(server); +static string? Normalize(ValueObject? v) +{ + if (v == null) return null; + var s = v.ToString(); + return string.IsNullOrWhiteSpace(s) ? null : s; +} + +static async Task Run(string server, string? username, string? tenantId, string? clientId, string? clientKey, string? authority="login.windows.net") +{ + var connection = new SeqConnection(server); - var user = await connection.Users.FindCurrentAsync(); - var provider = await connection.Settings.FindNamedAsync(SettingName.AuthenticationProvider); - var cid = await connection.Settings.FindNamedAsync(SettingName.AzureADClientId); - var ckey = await connection.Settings.FindNamedAsync(SettingName.AzureADClientKey); - var aut = await connection.Settings.FindNamedAsync(SettingName.AzureADAuthority); - var tid = await connection.Settings.FindNamedAsync(SettingName.AzureADTenantId); + var user = await connection.Users.FindCurrentAsync(); + var provider = await connection.Settings.FindNamedAsync(SettingName.AuthenticationProvider); + var cid = await connection.Settings.FindNamedAsync(SettingName.AzureADClientId); + var ckey = await connection.Settings.FindNamedAsync(SettingName.AzureADClientKey); + var aut = await connection.Settings.FindNamedAsync(SettingName.AzureADAuthority); + var tid = await connection.Settings.FindNamedAsync(SettingName.AzureADTenantId); - user.Username = username; - provider.Value = "Azure Active Directory"; - cid.Value = clientId; - ckey.Value = clientKey; - tid.Value = tenantId; - aut.Value = authority; + user.Username = username; + provider.Value = "Azure Active Directory"; + cid.Value = clientId; + ckey.Value = clientKey; + tid.Value = tenantId; + aut.Value = authority; - await connection.Users.UpdateAsync(user); - await connection.Settings.UpdateAsync(cid); - await connection.Settings.UpdateAsync(ckey); - await connection.Settings.UpdateAsync(tid); - await connection.Settings.UpdateAsync(aut); + await connection.Users.UpdateAsync(user); + await connection.Settings.UpdateAsync(cid); + await connection.Settings.UpdateAsync(ckey); + await connection.Settings.UpdateAsync(tid); + await connection.Settings.UpdateAsync(aut); - await connection.Settings.UpdateAsync(provider); // needs to go before IsAuthenticationEnabled but after the other settings - - var iae = await connection.Settings.FindNamedAsync(SettingName.IsAuthenticationEnabled); - iae.Value = true; - await connection.Settings.UpdateAsync(iae); // this update needs to happen last, as enabling auth will lock this connection out - } - } -} + await connection.Settings.UpdateAsync(provider); // needs to go before IsAuthenticationEnabled but after the other settings + + var iae = await connection.Settings.FindNamedAsync(SettingName.IsAuthenticationEnabled); + iae.Value = true; + await connection.Settings.UpdateAsync(iae); // this update needs to happen last, as enabling auth will lock this connection out +} \ No newline at end of file diff --git a/example/SeqEnableAAD/SeqEnableAAD.csproj b/example/SeqEnableAAD/SeqEnableAAD.csproj index 499ae03..77cb863 100644 --- a/example/SeqEnableAAD/SeqEnableAAD.csproj +++ b/example/SeqEnableAAD/SeqEnableAAD.csproj @@ -2,12 +2,13 @@ Exe - netcoreapp3.1 - SeqEnableAuth + net6.0 + seq-enable-aad + enable - + diff --git a/example/SeqQuery/Program.cs b/example/SeqQuery/Program.cs index 9a793a7..d48eabe 100644 --- a/example/SeqQuery/Program.cs +++ b/example/SeqQuery/Program.cs @@ -3,11 +3,7 @@ using DocoptNet; using Seq.Api; -namespace SeqQuery -{ - class Program - { - const string Usage = @"seq-query: run Seq SQL queries from your console. +const string usage = @"seq-query: run Seq SQL queries from your console. Usage: seq-query.exe [--apikey=] [--from=] [--to=] @@ -21,50 +17,42 @@ class Program "; - static void Main(string[] args) - { - Task.Run(async () => - { - try - { - var arguments = new Docopt().Apply(Usage, args, version: "Seq Query 0.1", exit: true); +try +{ + var arguments = new Docopt().Apply(usage, args, version: "Seq Query 0.1", exit: true)!; - var server = arguments[""].ToString(); - var query = Normalize(arguments[""]); - var apiKey = Normalize(arguments["--apikey"]); - var from = Normalize(arguments["--from"]); - var to = Normalize(arguments["--to"]); + var server = arguments[""].ToString(); + var query = Normalize(arguments[""]); + var apiKey = Normalize(arguments["--apikey"]); + var from = Normalize(arguments["--from"]); + var to = Normalize(arguments["--to"]); - await Run(server, apiKey, query, from, to); - } - catch (Exception ex) - { - Console.ForegroundColor = ConsoleColor.White; - Console.BackgroundColor = ConsoleColor.Red; - Console.WriteLine("seq-query: {0}", ex); - Console.ResetColor(); - Environment.Exit(-1); - } - }).Wait(); - } + await Run(server, apiKey, query, from, to); +} +catch (Exception ex) +{ + Console.ForegroundColor = ConsoleColor.White; + Console.BackgroundColor = ConsoleColor.Red; + Console.WriteLine("seq-query: {0}", ex); + Console.ResetColor(); + Environment.Exit(-1); +} - static string Normalize(ValueObject v) - { - if (v == null) return null; - var s = v.ToString(); - return string.IsNullOrWhiteSpace(s) ? null : s; - } +static string? Normalize(ValueObject? v) +{ + if (v == null) return null; + var s = v.ToString(); + return string.IsNullOrWhiteSpace(s) ? null : s; +} - static async Task Run(string server, string apiKey, string query, string from, string to) - { - var connection = new SeqConnection(server, apiKey); +static async Task Run(string server, string? apiKey, string? query, string? from, string? to) +{ + var connection = new SeqConnection(server, apiKey); - var now = DateTime.UtcNow; - var rangeStartUtc = from != null ? DateTime.Parse(from) : now - TimeSpan.FromDays(1); - DateTime? rangeEndUtc = to != null ? DateTime.Parse(to) : now; + var now = DateTime.UtcNow; + var rangeStartUtc = from != null ? DateTime.Parse(from) : now - TimeSpan.FromDays(1); + DateTime? rangeEndUtc = to != null ? DateTime.Parse(to) : now; - var result = await connection.Data.QueryCsvAsync(query, rangeStartUtc, rangeEndUtc); - Console.WriteLine(result); - } - } + var result = await connection.Data.QueryCsvAsync(query, rangeStartUtc, rangeEndUtc); + Console.WriteLine(result); } diff --git a/example/SeqQuery/SeqQuery.csproj b/example/SeqQuery/SeqQuery.csproj index ea3a4f4..a63bcac 100644 --- a/example/SeqQuery/SeqQuery.csproj +++ b/example/SeqQuery/SeqQuery.csproj @@ -1,9 +1,10 @@  - net461;netcoreapp2.2 - seq-query + net6.0 Exe + seq-query + enable @@ -11,7 +12,7 @@ - + diff --git a/example/SeqTail/Program.cs b/example/SeqTail/Program.cs index 0d98f85..0122366 100644 --- a/example/SeqTail/Program.cs +++ b/example/SeqTail/Program.cs @@ -8,11 +8,7 @@ using System.Threading; using Newtonsoft.Json.Linq; -namespace SeqTail -{ - class Program - { - const string Usage = @"seq-tail: watch a Seq query from your console. +const string usage = @"seq-tail: watch a Seq query from your console. Usage: seq-tail.exe [--filter=] [--apikey=] @@ -22,68 +18,60 @@ class Program -h --help Show this screen. --filter= Filter expression or free text to match. --apikey= Seq API key. +"; - "; +Log.Logger = new LoggerConfiguration() + .MinimumLevel.Verbose() + .WriteTo.Console() + .CreateLogger(); - static void Main(string[] args) - { - Log.Logger = new LoggerConfiguration() - .MinimumLevel.Verbose() - .WriteTo.Console() - .CreateLogger(); +TaskScheduler.UnobservedTaskException += (_,e) => Log.Fatal(e.Exception, "Unobserved task exception"); - TaskScheduler.UnobservedTaskException += (s,e) => Log.Fatal(e.Exception, "Unobserved task exception"); - - try - { - var arguments = new Docopt().Apply(Usage, args, version: "Seq Tail 0.2", exit: true); +try +{ + var arguments = new Docopt().Apply(usage, args, version: "Seq Tail 0.2", exit: true)!; - var server = arguments[""].ToString(); - var apiKey = Normalize(arguments["--apikey"]); - var filter = Normalize(arguments["--filter"]); + var server = arguments[""].ToString(); + var apiKey = Normalize(arguments["--apikey"]); + var filter = Normalize(arguments["--filter"]); - var cancel = new CancellationTokenSource(); - Console.WriteLine("Tailing, press Ctrl+C to exit."); - Console.CancelKeyPress += (s,a) => cancel.Cancel(); + var cancel = new CancellationTokenSource(); + Console.WriteLine("Tailing, press Ctrl+C to exit."); + Console.CancelKeyPress += (_,_) => cancel.Cancel(); - var run = Task.Run(() => Run(server, apiKey, filter, cancel), cancel.Token); + var run = Task.Run(() => Run(server, apiKey, filter, cancel), cancel.Token); - run.GetAwaiter().GetResult(); - } - catch (Exception ex) - { - Log.Fatal(ex, "Tailing aborted"); - Environment.Exit(-1); - } - } + run.GetAwaiter().GetResult(); +} +catch (Exception ex) +{ + Log.Fatal(ex, "Tailing aborted"); + Environment.Exit(-1); +} - static string Normalize(ValueObject v) - { - if (v == null) return null; - var s = v.ToString(); - return string.IsNullOrWhiteSpace(s) ? null : s; - } +static string? Normalize(ValueObject? v) +{ + if (v == null) return null; + var s = v.ToString(); + return string.IsNullOrWhiteSpace(s) ? null : s; +} - static async Task Run(string server, string apiKey, string filter, CancellationTokenSource cancel) - { - var connection = new SeqConnection(server, apiKey); +static async Task Run(string server, string? apiKey, string? filter, CancellationTokenSource cancel) +{ + var connection = new SeqConnection(server, apiKey); - string strict = null; - if (filter != null) - { - var converted = await connection.Expressions.ToStrictAsync(filter); - strict = converted.StrictExpression; - } + string? strict = null; + if (filter != null) + { + var converted = await connection.Expressions.ToStrictAsync(filter); + strict = converted.StrictExpression; + } - using (var stream = await connection.Events.StreamAsync(filter: strict)) - { - var subscription = stream - .Select(LogEventReader.ReadFromJObject) - .Subscribe(Log.Write, cancel.Cancel); + using var stream = await connection.Events.StreamAsync(filter: strict); + var subscription = stream + .Select(LogEventReader.ReadFromJObject) + .Subscribe(Log.Write, cancel.Cancel); - cancel.Token.WaitHandle.WaitOne(); - subscription.Dispose(); - } - } - } + cancel.Token.WaitHandle.WaitOne(); + subscription.Dispose(); } diff --git a/example/SeqTail/Properties/launchSettings.json b/example/SeqTail/Properties/launchSettings.json deleted file mode 100644 index 33fcc88..0000000 --- a/example/SeqTail/Properties/launchSettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "profiles": { - "seq-tail": { - "executablePath": "C:\\Development\\nblumhardt\\seq-api\\example\\SeqTail\\bin\\Debug\\net46\\win7-x64\\seq-tail.exe", - "commandLineArgs": "http://localhost:5341 --apikey=fSCcBOyOfttZ0kiZFgq" - } - } -} \ No newline at end of file diff --git a/example/SeqTail/SeqTail.csproj b/example/SeqTail/SeqTail.csproj index ac34313..9bf2168 100644 --- a/example/SeqTail/SeqTail.csproj +++ b/example/SeqTail/SeqTail.csproj @@ -1,9 +1,10 @@  - net461;netcoreapp2.2 + net6.0 seq-tail Exe + enable @@ -11,10 +12,10 @@ - - - - + + + + diff --git a/example/SignalCopy/Program.cs b/example/SignalCopy/Program.cs index 89b57cd..727a13b 100644 --- a/example/SignalCopy/Program.cs +++ b/example/SignalCopy/Program.cs @@ -5,11 +5,7 @@ using Seq.Api.Model.Signals; using System.Collections.Generic; -namespace SignalCopy -{ - class Program - { - const string Usage = @"signal-copy: copy Seq signals from one server to another. +const string usage = @"signal-copy: copy Seq signals from one server to another. Usage: signal-copy.exe [--srckey=] [--dstkey=] @@ -19,89 +15,80 @@ class Program -h --help Show this screen. --srckey= Source server API key. --dstkey= Destination server API key. +"; - "; +try +{ + var arguments = new Docopt().Apply(usage, args, version: "Seq Signal Copy 0.1", exit: true)!; - static void Main(string[] args) - { - Task.Run(async () => - { - try - { - var arguments = new Docopt().Apply(Usage, args, version: "Seq Signal Copy 0.1", exit: true); - - var src = arguments[""].ToString(); - var dst = arguments[""].ToString(); - var srcKey = Normalize(arguments["--srckey"]); - var dstKey = Normalize(arguments["--dstkey"]); - - await Run(src, srcKey, dst, dstKey); - } - catch (Exception ex) - { - Console.ForegroundColor = ConsoleColor.White; - Console.BackgroundColor = ConsoleColor.Red; - Console.WriteLine("signal-copy: {0}", ex); - Console.ResetColor(); - Environment.Exit(-1); - } - }).Wait(); - } + var src = arguments[""].ToString(); + var dst = arguments[""].ToString(); + var srcKey = Normalize(arguments["--srckey"]); + var dstKey = Normalize(arguments["--dstkey"]); - static string Normalize(ValueObject v) - { - if (v == null) return null; - var s = v.ToString(); - return string.IsNullOrWhiteSpace(s) ? null : s; - } + await Run(src, srcKey, dst, dstKey); +} +catch (Exception ex) +{ + Console.ForegroundColor = ConsoleColor.White; + Console.BackgroundColor = ConsoleColor.Red; + Console.WriteLine("signal-copy: {0}", ex); + Console.ResetColor(); + Environment.Exit(-1); +} - static async Task Run(string src, string srcKey, string dst, string dstKey) - { - var srcConnection = new SeqConnection(src, srcKey); - var dstConnection = new SeqConnection(dst, dstKey); +static string? Normalize(ValueObject? v) +{ + if (v == null) return null; + var s = v.ToString(); + return string.IsNullOrWhiteSpace(s) ? null : s; +} - var dstSignals = new Dictionary(); - foreach (var dstSignal in await dstConnection.Signals.ListAsync()) - { - if (dstSignals.ContainsKey(dstSignal.Title)) - { - Console.WriteLine($"The destination server has more than one signal named '{dstSignal.Title}'; only one copy of the signal will be updated."); - continue; - } +static async Task Run(string src, string? srcKey, string dst, string? dstKey) +{ + var srcConnection = new SeqConnection(src, srcKey); + var dstConnection = new SeqConnection(dst, dstKey); - dstSignals.Add(dstSignal.Title, dstSignal); - } + var dstSignals = new Dictionary(); + foreach (var dstSignal in await dstConnection.Signals.ListAsync()) + { + if (dstSignals.ContainsKey(dstSignal.Title)) + { + Console.WriteLine($"The destination server has more than one signal named '{dstSignal.Title}'; only one copy of the signal will be updated."); + continue; + } + + dstSignals.Add(dstSignal.Title, dstSignal); + } - var count = 0; + var count = 0; - foreach (var signal in await srcConnection.Signals.ListAsync()) + foreach (var signal in await srcConnection.Signals.ListAsync()) + { + if (dstSignals.TryGetValue(signal.Title, out var target)) + { + if (target.IsProtected) { - if (dstSignals.TryGetValue(signal.Title, out var target)) - { - if (target.IsProtected) - { - Console.WriteLine($"Skipping restricted signal '{signal.Title}' ({target.Id})"); - continue; - } - - Console.WriteLine($"Updating existing signal '{signal.Title}' ({target.Id})"); - } - else - { - Console.WriteLine($"Creating new signal '{signal.Title}'"); - target = await dstConnection.Signals.TemplateAsync(); - } - - target.Title = signal.Title; - target.Filters = signal.Filters; - target.Columns = signal.Columns; - target.Description = signal.Description + " (copy)"; - - await (target.Id != null ? dstConnection.Signals.UpdateAsync(target) : dstConnection.Signals.AddAsync(target)); - ++count; + Console.WriteLine($"Skipping restricted signal '{signal.Title}' ({target.Id})"); + continue; } - Console.WriteLine($"Done, {count} signals updated."); + Console.WriteLine($"Updating existing signal '{signal.Title}' ({target.Id})"); + } + else + { + Console.WriteLine($"Creating new signal '{signal.Title}'"); + target = await dstConnection.Signals.TemplateAsync(); } + + target.Title = signal.Title; + target.Filters = signal.Filters; + target.Columns = signal.Columns; + target.Description = signal.Description + " (copy)"; + + await (target.Id != null ? dstConnection.Signals.UpdateAsync(target) : dstConnection.Signals.AddAsync(target)); + ++count; } + + Console.WriteLine($"Done, {count} signals updated."); } diff --git a/example/SignalCopy/Properties/launchSettings.json b/example/SignalCopy/Properties/launchSettings.json deleted file mode 100644 index 16428f3..0000000 --- a/example/SignalCopy/Properties/launchSettings.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "profiles": { - "SignalCopy": { - "commandName": "Project", - "commandLineArgs": "http://localhost:5341 http://localhost:5342" - } - } -} \ No newline at end of file diff --git a/example/SignalCopy/SignalCopy.csproj b/example/SignalCopy/SignalCopy.csproj index 9b9700e..019cb75 100644 --- a/example/SignalCopy/SignalCopy.csproj +++ b/example/SignalCopy/SignalCopy.csproj @@ -1,9 +1,10 @@  - net461;netcoreapp2.2 + net6.0 signal-copy Exe + enable @@ -11,7 +12,7 @@ - + diff --git a/src/Seq.Api/Seq.Api.csproj b/src/Seq.Api/Seq.Api.csproj index ff877f5..c82cbbd 100644 --- a/src/Seq.Api/Seq.Api.csproj +++ b/src/Seq.Api/Seq.Api.csproj @@ -1,7 +1,7 @@ Client library for the Seq HTTP API. - 2023.2.0 + 2023.3.0 Datalust;Contributors netstandard2.0;net6.0 true diff --git a/test/Seq.Api.Tests/Seq.Api.Tests.csproj b/test/Seq.Api.Tests/Seq.Api.Tests.csproj index 8885638..6c00170 100644 --- a/test/Seq.Api.Tests/Seq.Api.Tests.csproj +++ b/test/Seq.Api.Tests/Seq.Api.Tests.csproj @@ -10,9 +10,12 @@ - - - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + \ No newline at end of file