### List Installed Apps with Seq.Api Source: https://github.com/datalust/seq-api/blob/dev/README.md Demonstrates how to access resource groups exposed as properties of the SeqConnection object. This example retrieves a list of installed applications on Seq. ```csharp var connection = new SeqConnection("http://localhost:5341"); var installedApps = await connection.Apps.ListAsync(); ``` -------------------------------- ### Manage Seq Apps and App Instances with C# Source: https://context7.com/datalust/seq-api/llms.txt Provides C# code examples for listing installed Seq apps, listing running app instances, and creating new app instances with specific settings. This snippet requires the Seq.Api NuGet package. ```csharp var connection = new SeqConnection("http://localhost:5341", "api-key"); // List installed apps var apps = await connection.Apps.ListAsync(); foreach (var app in apps) { Console.WriteLine($"{app.Title} v{app.PackageIdentity.Version}"); Console.WriteLine($" Package: {app.PackageIdentity.Id}"); } // List running app instances var instances = await connection.AppInstances.ListAsync(); foreach (var instance in instances) { Console.WriteLine($"{instance.Title} ({instance.Id})"); Console.WriteLine($" Invocations: {instance.InvocationCount}"); } // Create app instance var appInstance = await connection.AppInstances.TemplateAsync(); appInstance.Title = "Slack Notifier"; appInstance.AppId = "seq-app-slack"; appInstance.Settings = new Dictionary { ["webhookUrl"] = "https://hooks.slack.com/services/YOUR/WEBHOOK/URL", ["channel"] = "#alerts" }; await connection.AppInstances.AddAsync(appInstance); ``` -------------------------------- ### Navigate API Resources with SeqApiClient Source: https://github.com/datalust/seq-api/blob/dev/README.md Demonstrates how to use the SeqApiClient to navigate the API's resource hierarchy. It starts by getting the root resource and then retrieves specific resource groups like 'EventsResources'. ```csharp var root = await client.GetRootAsync(); var events = await client.GetAsync(root, "EventsResources"); ``` -------------------------------- ### Install Seq.Api NuGet Package Source: https://github.com/datalust/seq-api/blob/dev/README.md Installs the Seq.Api NuGet package into your .NET project. This package provides the C# representations and helper classes for interacting with the Seq HTTP API. ```powershell dotnet add package Seq.Api ``` -------------------------------- ### Use Seq Low-Level API Client with C# Source: https://context7.com/datalust/seq-api/llms.txt Demonstrates interacting with the Seq API using the low-level `SeqApiClient` in C#. This includes getting the server root, navigating resource groups, listing events with filters, and getting raw string responses. Requires the Seq.Api.Client NuGet package. ```csharp using Seq.Api.Client; var client = new SeqApiClient("http://localhost:5341", "api-key"); try { // Get root resource var root = await client.GetRootAsync(); Console.WriteLine($"Server version: {root.ServerVersion}"); // Navigate to resource groups var events = await client.GetAsync(root, "EventsResources"); // List events using low-level API var matched = await client.ListAsync( events, "Items", new Dictionary { { "count", 10 }, { "render", true }, { "filter", "@Level = 'Error'" } }); foreach (var evt in matched) { Console.WriteLine(evt.RenderedMessage); } // Get string response var serverStatus = await client.GetStringAsync(root, "DiagnosticsResources"); Console.WriteLine(serverStatus); } finally { client.Dispose(); } ``` -------------------------------- ### List Events using SeqApiClient Source: https://github.com/datalust/seq-api/blob/dev/README.md Shows how to use the SeqApiClient to list entities, such as events, by navigating links and specifying query parameters. This example retrieves a list of events with rendering enabled. ```csharp var matched = await client.ListAsync( events, "Items", new Dictionary{{"count", 10}, {"render", true}}); foreach (var match in matched) Console.WriteLine(match.RenderedMessage); ``` -------------------------------- ### Manage Seq Signals (Create, List, Update, Delete) in C# Source: https://context7.com/datalust/seq-api/llms.txt This C# example shows how to manage signals within Seq, including creating new signals from templates, listing existing signals, finding specific signals, updating their properties, and deleting them. It utilizes the Seq.Api library. ```csharp var connection = new SeqConnection("http://localhost:5341", "api-key"); // Create new signal from template var signal = await connection.Signals.TemplateAsync(); signal.Title = "Production Errors"; signal.Description = "All errors from production environment"; signal.Filters = new List { new SignalFilterPart { Filter = "@Level = 'Error' and Environment = 'Production'" } }; var created = await connection.Signals.AddAsync(signal); Console.WriteLine($"Created signal with ID: {created.Id}"); // List all signals var allSignals = await connection.Signals.ListAsync(shared: true); foreach (var s in allSignals) { Console.WriteLine($"{s.Title} ({s.Id}): {s.Description}"); } // Find and update existing signal var existing = await connection.Signals.FindAsync(created.Id); existing.Description = "Updated description"; await connection.Signals.UpdateAsync(existing); // Delete signal await connection.Signals.RemoveAsync(existing); ``` -------------------------------- ### Execute SQL Queries and Get Results in C# Source: https://context7.com/datalust/seq-api/llms.txt This C# snippet demonstrates how to execute SQL-like queries against Seq data using the Seq.Api library. It shows how to retrieve results in both CSV format and structured row format, specifying query parameters like time ranges and timeouts. ```csharp var connection = new SeqConnection("http://localhost:5341", "api-key"); // Execute query and get CSV results var csvResult = await connection.Data.QueryCsvAsync( query: "select count(*) as ErrorCount, Application from stream where @Level = 'Error' group by Application order by ErrorCount desc", rangeStartUtc: DateTime.UtcNow.AddDays(-1), rangeEndUtc: DateTime.UtcNow, timeout: TimeSpan.FromSeconds(30) ); Console.WriteLine(csvResult); // Output: // ErrorCount,Application // 42,WebApp // 15,BackgroundService // Execute query and get structured results var structuredResult = await connection.Data.QueryAsync( query: "select @Timestamp, @Message, Application from stream where @Level = 'Warning' limit 100", rangeStartUtc: DateTime.UtcNow.AddHours(-6) ); foreach (var row in structuredResult.Rows) { Console.WriteLine($"{row[0]}: {row[1]} [{row[2]}]"); } ``` -------------------------------- ### Creating a Connection Source: https://context7.com/datalust/seq-api/llms.txt Demonstrates how to establish a connection to a Seq server using different authentication methods and configurations. ```APIDOC ## Creating a Connection ### Description Establishing a connection to a Seq server. ### Method Instantiate `SeqConnection` class. ### Endpoint Not applicable (client-side library). ### Parameters #### Path Parameters None. #### Query Parameters None. #### Request Body None. ### Request Example ```csharp using Seq.Api; // Basic connection with server URL only var connection = new SeqConnection("http://localhost:5341"); // Connection with API key for authentication (user-level access required) var apiKey = "your-api-key-here"; var connection = new SeqConnection("http://seq.example.com", apiKey); // Connection with custom HTTP message handler var connection = new SeqConnection( "https://seq.example.com", apiKey: "your-key", createHttpMessageHandler: cookies => new HttpClientHandler { CookieContainer = cookies, UseDefaultCredentials = true } ); // Ensure server is reachable with timeout try { await connection.EnsureConnectedAsync(TimeSpan.FromSeconds(30)); Console.WriteLine("Connected successfully"); } catch (SeqApiException ex) { Console.WriteLine($"Connection failed: {ex.Message}"); } // Always dispose when done connection.Dispose(); ``` ### Response #### Success Response (200) Connection established successfully. #### Response Example None (client-side operation). ``` -------------------------------- ### Manage Seq Users and API Keys with C# Source: https://context7.com/datalust/seq-api/llms.txt Demonstrates creating and managing users and API keys using the Seq API client in C#. It covers creating new users, listing existing users, creating new API keys with specific permissions, and listing existing API keys. Requires the Seq.Api NuGet package. ```csharp var connection = new SeqConnection("http://localhost:5341", "admin-api-key"); // Create new user var user = await connection.Users.TemplateAsync(); user.Username = "developer@example.com"; user.DisplayName = "Developer"; user.EmailAddress = "developer@example.com"; var createdUser = await connection.Users.AddAsync(user); Console.WriteLine($"Created user: {createdUser.Id}"); // List all users var users = await connection.Users.ListAsync(); foreach (var u in users) { Console.WriteLine($"{u.DisplayName} ({u.Username}): {u.EmailAddress}"); } // Create API key var apiKey = await connection.ApiKeys.TemplateAsync(); apiKey.Title = "CI/CD Pipeline Key"; apiKey.AppliedPermissions = new[] { "Read", "Write" }; var createdKey = await connection.ApiKeys.AddAsync(apiKey); Console.WriteLine($"API Key Token: {createdKey.Token}"); // List API keys var keys = await connection.ApiKeys.ListAsync(); foreach (var k in keys) { Console.WriteLine($"{k.Title} (Owner: {k.OwnerId})"); } ``` -------------------------------- ### Create Seq Connection in C# Source: https://context7.com/datalust/seq-api/llms.txt Demonstrates how to establish a connection to a Seq server using the SeqConnection class. It covers basic URL-based connections, authentication with API keys, and custom HTTP message handler configurations. Includes error handling for connection attempts and emphasizes the importance of disposing the connection object. ```csharp using Seq.Api; // Basic connection with server URL only var connection = new SeqConnection("http://localhost:5341"); // Connection with API key for authentication (user-level access required) var apiKey = "your-api-key-here"; var connection = new SeqConnection("http://seq.example.com", apiKey); // Connection with custom HTTP message handler var connection = new SeqConnection( "https://seq.example.com", apiKey: "your-key", createHttpMessageHandler: cookies => new HttpClientHandler { CookieContainer = cookies, UseDefaultCredentials = true } ); // Ensure server is reachable with timeout try { await connection.EnsureConnectedAsync(TimeSpan.FromSeconds(30)); Console.WriteLine("Connected successfully"); } catch (SeqApiException ex) { Console.WriteLine($"Connection failed: {ex.Message}"); } // Always dispose when done connection.Dispose(); ``` -------------------------------- ### Initialize SeqApiClient Source: https://github.com/datalust/seq-api/blob/dev/README.md Creates a low-level SeqApiClient instance for direct interaction with the Seq API. This client is useful for scenarios not covered by the higher-level SeqConnection wrapper. ```csharp var client = new SeqApiClient("http://localhost:5341"); ``` -------------------------------- ### Authenticating with User Credentials Source: https://context7.com/datalust/seq-api/llms.txt Details on how to log in to a Seq server using username and password for authentication. ```APIDOC ## Authenticating with User Credentials ### Description Logging in with username and password. ### Method `SeqConnection.Users.LoginAsync` and `SeqConnection.Users.FindCurrentAsync`. ### Endpoint Not applicable (client-side library). ### Parameters #### Path Parameters None. #### Query Parameters None. #### Request Body None. ### Request Example ```csharp var connection = new SeqConnection("http://localhost:5341"); try { // Login with username/password (Active Directory or local auth) var user = await connection.Users.LoginAsync("admin", "password123"); Console.WriteLine($"Logged in as: {user.Username}"); Console.WriteLine($"User ID: {user.Id}"); // Get current logged-in user var currentUser = await connection.Users.FindCurrentAsync(); Console.WriteLine($"Current user email: {currentUser.EmailAddress}"); // Perform authenticated operations var signals = await connection.Signals.ListAsync(); // Logout when done await connection.Users.LogoutAsync(); } catch (SeqApiException ex) { Console.WriteLine($"Authentication failed: {ex.Message} (HTTP {ex.StatusCode})"); } ``` ### Response #### Success Response (200) User object representing the logged-in user. #### Response Example ```json { "id": "user-123", "username": "admin", "emailAddress": "admin@example.com" } ``` #### Error Response (401) Authentication failed. #### Error Response Example ```json { "error": "Invalid credentials" } ``` ``` -------------------------------- ### Create a New Signal Entity Source: https://github.com/datalust/seq-api/blob/dev/README.md Shows the pattern for creating new entities in Seq using the API client. It first retrieves a template for the entity, populates its properties, and then adds it to Seq. ```csharp var signal = await connection.Signals.TemplateAsync(); signal.Title = "Signal 123"; await connection.Signals.AddAsync(signal); ``` -------------------------------- ### Create SeqConnection Object Source: https://github.com/datalust/seq-api/blob/dev/README.md Initializes a SeqConnection object, which is the primary entry point for interacting with the Seq API. It requires the Seq server URL. Authentication can be handled via an API key or user credentials. ```csharp var connection = new SeqConnection("http://localhost:5341"); // For authentication with an API key: // var connection = new SeqConnection("http://localhost:5341", apiKey: "YOUR_API_KEY"); // For authentication with username and password: // await connection.Users.LoginAsync(username, password); ``` -------------------------------- ### Authenticate Seq API with User Credentials in C# Source: https://context7.com/datalust/seq-api/llms.txt Illustrates how to authenticate with a Seq server using username and password credentials. This snippet shows logging in, retrieving the logged-in user's details, performing an authenticated operation (listing signals), and logging out. It includes error handling for authentication failures. ```csharp var connection = new SeqConnection("http://localhost:5341"); try { // Login with username/password (Active Directory or local auth) var user = await connection.Users.LoginAsync("admin", "password123"); Console.WriteLine($"Logged in as: {user.Username}"); Console.WriteLine($"User ID: {user.Id}"); // Get current logged-in user var currentUser = await connection.Users.FindCurrentAsync(); Console.WriteLine($"Current user email: {currentUser.EmailAddress}"); // Perform authenticated operations var signals = await connection.Signals.ListAsync(); // Logout when done await connection.Users.LogoutAsync(); } catch (SeqApiException ex) { Console.WriteLine($"Authentication failed: {ex.Message} (HTTP {ex.StatusCode})"); } ``` -------------------------------- ### Manage Seq Dashboards and Charts with C# Source: https://context7.com/datalust/seq-api/llms.txt Shows how to create, list, and update dashboards using the Seq API client in C#. This includes templating new dashboards, adding them, listing existing shared dashboards, and updating their properties. Requires the Seq.Api NuGet package. ```csharp var connection = new SeqConnection("http://localhost:5341", "api-key"); // Create dashboard var dashboard = await connection.Dashboards.TemplateAsync(); dashboard.Title = "System Health"; dashboard.Description = "Real-time system metrics"; var created = await connection.Dashboards.AddAsync(dashboard); Console.WriteLine($"Dashboard created: {created.Id}"); // List dashboards var dashboards = await connection.Dashboards.ListAsync(shared: true); foreach (var d in dashboards) { Console.WriteLine($"{d.Title}: {d.Description}"); } // Update dashboard var existing = await connection.Dashboards.FindAsync(created.Id); existing.Description = "Updated health dashboard"; await connection.Dashboards.UpdateAsync(existing); ``` -------------------------------- ### Stream Live Events via WebSockets in C# Source: https://context7.com/datalust/seq-api/llms.txt This C# snippet demonstrates how to subscribe to real-time event streams from Seq using WebSockets. It configures Serilog to output streamed events and parses them in compact JSON format. Requires the Seq.Api and Serilog.Formatting.Compact.Reader NuGet packages. ```csharp using Seq.Api; using Serilog; using Serilog.Formatting.Compact.Reader; var connection = new SeqConnection("http://localhost:5341", "api-key"); // Configure Serilog to output streamed events Log.Logger = new LoggerConfiguration() .MinimumLevel.Verbose() .WriteTo.Console() .CreateLogger(); // Stream events matching filter in real-time var cts = new CancellationTokenSource(); Console.CancelKeyPress += (s, e) => { cts.Cancel(); e.Cancel = true; }; try { await foreach (var evt in connection.Events.StreamDocumentsAsync( filter: "@Level = 'Error'", clef: true, render: true, cancellationToken: cts.Token)) { // Parse compact JSON format back to LogEvent var logEvent = LogEventReader.ReadFromString(evt); Log.Write(logEvent); } } catch (OperationCanceledException) { Console.WriteLine("Stream terminated"); } ``` -------------------------------- ### Manage Seq Retention Policies with C# Source: https://context7.com/datalust/seq-api/llms.txt This C# code snippet demonstrates how to interact with Seq retention policies. It covers creating a new policy, listing existing policies, and updating an existing one. It requires the Seq.Api library and a running Seq instance with an API key. ```csharp var connection = new SeqConnection("http://localhost:5341", "api-key"); // Create retention policy var policy = await connection.RetentionPolicies.TemplateAsync(); policy.RetentionMinutes = 10080; // 7 days policy.SignalExpression = new SignalExpressionPart { Filter = "@Level = 'Verbose' or @Level = 'Debug'" }; var created = await connection.RetentionPolicies.AddAsync(policy); Console.WriteLine($"Created retention policy: {created.Id}"); // List policies var policies = await connection.RetentionPolicies.ListAsync(); foreach (var p in policies) { var hours = p.RetentionMinutes / 60.0; Console.WriteLine($"Policy {p.Id}: Retain {hours}h for filter '{p.SignalExpression?.Filter}'"); } // Update policy var existing = await connection.RetentionPolicies.FindAsync(created.Id); existing.RetentionMinutes = 20160; // 14 days await connection.RetentionPolicies.UpdateAsync(existing); ``` -------------------------------- ### Enable Seq AAD Integration via CLI Source: https://github.com/datalust/seq-api/blob/dev/example/SeqEnableAAD/README.md This command enables Azure Active Directory integration for Seq by specifying the Seq instance URL and AAD credentials. Ensure you replace the placeholder values with your actual details. ```bash seq-enable-aad.exe https://seq.example.com --uname=example@microsoft.com --clientid=xxxxxx --tenantid=xxxxxx --clientkey=xxxxxx --authority=login.windows.net ``` -------------------------------- ### Configure Seq BASE_URI (Linux/Docker) Source: https://github.com/datalust/seq-api/blob/dev/example/SeqEnableAAD/README.md Sets the BASE_URI environment variable for Seq when running in a Docker container on Linux. This URI serves as the reply address for Azure Active Directory authentication. ```bash docker run -d \ --restart unless-stopped \ --name seq \ -p 5341:80 \ -e ACCEPT_EULA=Y \ -e BASE_URI=https://seq.example.com \ datalust/seq:latest ``` -------------------------------- ### Configure Seq Canonical URI (Windows) Source: https://github.com/datalust/seq-api/blob/dev/example/SeqEnableAAD/README.md Sets the canonical URI for Seq on Windows, which is used as a reply address for Azure Active Directory authentication. This is a two-step process involving configuration and service restart. ```bash seq config -k api.canonicalUri -v https://seq.example.com seq service restart ``` -------------------------------- ### Copy Seq Signals Between Servers in C# Source: https://context7.com/datalust/seq-api/llms.txt This C# code synchronizes signals from a source Seq server to a destination server. It lists signals on both servers, compares them by title, and either updates existing signals or creates new ones on the destination. It requires the Seq.Api library. ```csharp var srcConnection = new SeqConnection("http://source.example.com", "src-key"); var dstConnection = new SeqConnection("http://dest.example.com", "dst-key"); // Build dictionary of destination signals var dstSignals = new Dictionary(); foreach (var dstSignal in await dstConnection.Signals.ListAsync()) { if (!dstSignals.ContainsKey(dstSignal.Title)) dstSignals.Add(dstSignal.Title, dstSignal); } // Copy signals from source foreach (var signal in await srcConnection.Signals.ListAsync()) { SignalEntity target; if (dstSignals.TryGetValue(signal.Title, out target)) { if (target.IsProtected) continue; Console.WriteLine($"Updating '{signal.Title}'"); } else { Console.WriteLine($"Creating '{signal.Title}'"); target = await dstConnection.Signals.TemplateAsync(); } target.Title = signal.Title; target.Filters = signal.Filters; target.Columns = signal.Columns; target.Description = signal.Description; if (target.Id != null) await dstConnection.Signals.UpdateAsync(target); else await dstConnection.Signals.AddAsync(target); } ``` -------------------------------- ### Querying Events Source: https://context7.com/datalust/seq-api/llms.txt Shows how to retrieve events from Seq using filters, date ranges, and rendering options. ```APIDOC ## Querying Events ### Description Retrieving events with filters and rendering. ### Method `SeqConnection.Events.ListAsync` and `SeqConnection.Expressions.ToStrictAsync`. ### Endpoint Not applicable (client-side library). ### Parameters #### Path Parameters None. #### Query Parameters None. #### Request Body None. ### Request Example ```csharp var connection = new SeqConnection("http://localhost:5341", "api-key"); // Query with filter expression (strict format required) var events = await connection.Events.ListAsync( filter: "@Level = 'Error' and @Exception is not null", count: 100, render: true, fromDateUtc: DateTime.UtcNow.AddHours(-24), toDateUtc: DateTime.UtcNow ); foreach (var evt in events) { Console.WriteLine($"[{evt.Timestamp:yyyy-MM-dd HH:mm:ss}] {evt.RenderedMessage}"); if (evt.Exception != null) Console.WriteLine($" Exception: {evt.Exception}"); } // Convert fuzzy filter to strict format var fuzzyFilter = "error database timeout"; var converted = await connection.Expressions.ToStrictAsync(fuzzyFilter); var strictEvents = await connection.Events.ListAsync( filter: converted.StrictExpression, count: 50, render: true ); ``` ### Response #### Success Response (200) A list of events matching the query. #### Response Example ```json [ { "id": "evt-123", "timestamp": "2023-10-27T10:30:00Z", "level": "Error", "messageTemplate": "An error occurred in the database: {ErrorMessage}", "renderedMessage": "An error occurred in the database: Timeout expired", "properties": { "ErrorMessage": "Timeout expired" }, "exception": "System.TimeoutException: ..." } ] ``` #### Error Response (400) Invalid filter expression or parameters. #### Error Response Example ```json { "error": "Invalid filter expression" } ``` ``` -------------------------------- ### Query Seq Events with Filters in C# Source: https://context7.com/datalust/seq-api/llms.txt Shows how to retrieve events from a Seq server using specific filters, time ranges, and rendering options. This snippet demonstrates querying events based on level and exceptions, converting fuzzy filters to strict expressions, and iterating through the results. It utilizes the `ListAsync` method for fetching events. ```csharp var connection = new SeqConnection("http://localhost:5341", "api-key"); // Query with filter expression (strict format required) var events = await connection.Events.ListAsync( filter: "@Level = 'Error' and @Exception is not null", count: 100, render: true, fromDateUtc: DateTime.UtcNow.AddHours(-24), toDateUtc: DateTime.UtcNow ); foreach (var evt in events) { Console.WriteLine($"[{evt.Timestamp:yyyy-MM-dd HH:mm:ss}] {evt.RenderedMessage}"); if (evt.Exception != null) Console.WriteLine($" Exception: {evt.Exception}"); } // Convert fuzzy filter to strict format var fuzzyFilter = "error database timeout"; var converted = await connection.Expressions.ToStrictAsync(fuzzyFilter); var strictEvents = await connection.Events.ListAsync( filter: converted.StrictExpression, count: 50, render: true ); ``` -------------------------------- ### Enumerating Large Event Sets Source: https://context7.com/datalust/seq-api/llms.txt Provides an efficient way to stream all matching events from Seq, suitable for large datasets. ```APIDOC ## Enumerating Large Event Sets ### Description Efficiently streaming all matching events. ### Method `SeqConnection.Events.EnumerateAsync`. ### Endpoint Not applicable (client-side library). ### Parameters #### Path Parameters None. #### Query Parameters None. #### Request Body None. ### Request Example ```csharp var connection = new SeqConnection("http://localhost:5341", "api-key"); // Enumerate events lazily (uses WebSockets, memory efficient) var eventCount = 0; await foreach (var evt in connection.Events.EnumerateAsync( filter: "Environment = 'Production'", render: true, count: 10000, fromDateUtc: DateTime.UtcNow.AddDays(-7))) { Console.WriteLine($"{evt.Timestamp}: {evt.RenderedMessage}"); eventCount++; // Process in batches if (eventCount % 1000 == 0) Console.WriteLine($"Processed {eventCount} events..."); } Console.WriteLine($"Total events: {eventCount}"); ``` ### Response #### Success Response (200) An asynchronous stream of events matching the query. #### Response Example Individual event objects are yielded as they are received, for example: ```json { "id": "evt-456", "timestamp": "2023-10-26T15:00:00Z", "level": "Information", "messageTemplate": "User logged in: {Username}", "renderedMessage": "User logged in: testuser", "properties": { "Username": "testuser" } } ``` #### Error Response (500) Internal server error during event streaming. #### Error Response Example ```json { "error": "An unexpected error occurred" } ``` ``` -------------------------------- ### Enumerate Events with Filtering Source: https://github.com/datalust/seq-api/blob/dev/README.md Demonstrates how to lazily enumerate through a set of events matching a specific filter. It handles potential pagination by retrieving results in chunks. The `render` parameter ensures the message is rendered. ```csharp var resultSet = connection.Events.EnumerateAsync( filter: "Environment = 'Test'", render: true, count: 1000); await foreach (var evt in resultSet) Console.WriteLine(evt.RenderedMessage); ``` -------------------------------- ### Stream Events via WebSocket Source: https://github.com/datalust/seq-api/blob/dev/README.md Enables live streaming of events that match a given filter over a WebSocket connection. Events are received in compact JSON format and can be deserialized into JObjects or Serilog LogEvents. ```csharp var filter = "@Level = 'Error'"; await foreach (var evt in connection.Events.StreamAsync(filter: filter, clef: true)) { var logEvent = LogEventReader.ReadFromString(evt); Log.Write(logEvent); } ``` -------------------------------- ### Enumerate Seq Events Efficiently in C# Source: https://context7.com/datalust/seq-api/llms.txt Explains how to efficiently enumerate a large set of matching events from a Seq server using the `EnumerateAsync` method. This approach utilizes WebSockets for memory efficiency and allows for lazy processing of events within specified filters and time ranges. It includes a counter for processed events. ```csharp var connection = new SeqConnection("http://localhost:5341", "api-key"); // Enumerate events lazily (uses WebSockets, memory efficient) var eventCount = 0; await foreach (var evt in connection.Events.EnumerateAsync( filter: "Environment = 'Production'", render: true, count: 10000, fromDateUtc: DateTime.UtcNow.AddDays(-7))) { Console.WriteLine($"{evt.Timestamp}: {evt.RenderedMessage}"); eventCount++; // Process in batches if (eventCount % 1000 == 0) Console.WriteLine($"Processed {eventCount} events..."); } Console.WriteLine($"Total events: {eventCount}"); ``` -------------------------------- ### Delete Seq Events with C# Source: https://context7.com/datalust/seq-api/llms.txt Illustrates how to delete events from Seq based on specified criteria using the Seq API client in C#. This includes deleting events within a date range and environment, and deleting events associated with a specific signal. Requires the Seq.Api NuGet package. ```csharp var connection = new SeqConnection("http://localhost:5341", "api-key"); // Delete old events from specific environment var result = await connection.Events.DeleteAsync( filter: "Environment = 'Development'", fromDateUtc: DateTime.UtcNow.AddMonths(-6), toDateUtc: DateTime.UtcNow.AddMonths(-3) ); Console.WriteLine($"Deleted {result.Count} events"); // Delete events using signal var signal = await connection.Signals.FindAsync("signal-12345"); var deleteResult = await connection.Events.DeleteAsync( unsavedSignal: signal, fromDateUtc: DateTime.UtcNow.AddDays(-90) ); Console.WriteLine($"Removed {deleteResult.Count} events matching signal"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.