FAQ — Generate Batch Log Events (PowerShell 7)
Section titled “FAQ — Generate Batch Log Events (PowerShell 7)”This FAQ shows how to generate batches of Nodinite JSON Log Events for demos, load testing, and training environments using PowerShell 7.
What you'll find on this page:
- Batch generation script - Create hundreds of realistic order events for testing
- Ready-to-use examples - Copy, customize, and run immediately with PowerShell 7
- Pickup Service integration - Files written in the correct format for asynchronous delivery
- Randomized data - Realistic cities, order IDs, timestamps, and processing times
Jump to section: Understanding Log Event Generation | Batch Generation | Script Details
Understanding Log Event Generation
Section titled “Understanding Log Event Generation”Nodinite Log Events are JSON files that contain structured logging data. When you need to test your logging infrastructure or create demo environments, manually creating hundreds of events is impractical. This PowerShell 7 script automates the process by:
- Generating valid JSON - Each file matches the Log Event schema
- Simulating realistic data - Random cities, order IDs, timestamps, and processing times
- Base64-encoding payloads - The
Bodyfield contains base64-encoded JSON (as required) - Randomizing timestamps - Events scattered throughout earlier today (simulates organic traffic)
- Adding context properties - Business identifiers like Order IDs and cities for searchability
The generated files can be consumed by the Pickup Service for asynchronous delivery to the Log API, or sent directly to the Log API with Log using REST. The Logging Service then processes them.
Why PowerShell 7? PowerShell 7 provides better JSON handling with ConvertTo-Json -Depth, improved UTF-8 encoding without BOM, and cross-platform compatibility. These features ensure the generated Log Events are correctly formatted for Nodinite.
Learn more: Log Event structure | JSON Log Event schema | Pickup Service overview | Install PowerShell 7
Batch Generation: Order Events
Section titled “Batch Generation: Order Events”Generate multiple order events with randomized data for demo or load testing purposes.
Configuration options: Customize LogAgentValueId, EndPointName, MessageType, and order count parameters. Files are written to the specified output folder in UTF-8 format (no BOM) for compatibility with the Pickup Service.
Usage (quick)
Section titled “Usage (quick)”Open PowerShell 7 terminal and run:
pwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 150 -OutputFolder 'C:\temp\logevents'This will create 150 JSON files in the target folder with LogDateTime values scattered earlier today.
Verify PowerShell 7: Run
$PSVersionTable.PSVersionto confirm you're using PowerShell 7.0 or later. Download PowerShell 7 if needed.
Script: Generate-Nodinite-LogEvents.ps1
Section titled “Script: Generate-Nodinite-LogEvents.ps1”Save this file next to your documentation or in a demo folder. It uses PowerShell 7 features for improved JSON handling and UTF-8 encoding.
#!/usr/bin/env pwsh#Requires -Version 7.0<#.SYNOPSISGenerates Nodinite-style LogEvent JSON files for demo/load-testing.
.DESCRIPTIONThis PowerShell 7 script creates realistic Log Event JSON files for testing Nodinite.* Requires PowerShell 7.0 or later* Each file contains a single LogEvent object* UTF-8 encoding without BOM* Randomized data for realistic testing
.PARAMETER OrderCountNumber of order events to generate (default: 150)
.PARAMETER OutputFolderDestination folder for generated JSON files (default: C:\temp\logevents)
.EXAMPLEpwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 150 -OutputFolder 'C:\temp\logevents'#>param( [int]$OrderCount = 150, [string]$OutputFolder = 'C:\temp\logevents', [int]$RowsMin = 1, [int]$RowsMax = 9, [int]$LogAgentValueId = 42, [string]$EndPointName = 'INT101: Demo Log Events', [string]$MessageType = 'Demo.Order/1.0')
# Ensure folder existsif (-not (Test-Path -Path $OutputFolder)) { New-Item -Path $OutputFolder -ItemType Directory -Force | Out-Null}
# City list for variety$cities = @( 'New York','London','Tokyo','Sydney','Mumbai','São Paulo','Cairo','Nairobi','Moscow','Berlin', 'Paris','Madrid','Rome','Lisbon','Oslo','Stockholm','Helsinki','Reykjavik','Dubai','Singapore', 'Hong Kong','Seoul','Beijing','Jakarta','Bangkok','Manila','Mexico City','Vancouver','Toronto','Los Angeles')
# Helper: base64 encode textfunction To-Base64([string]$text) { return [Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($text))}
# Determine a start time "some time ago today" (random earlier time today)$now = Get-Date$maxHours = [Math]::Max(1, $now.Hour)$startHour = Get-Random -Minimum 1 -Maximum ($maxHours + 1)$startMinute = Get-Random -Minimum 0 -Maximum 59$startSecond = Get-Random -Minimum 0 -Maximum 59$startDate = $now.Date.AddHours($startHour).AddMinutes($startMinute).AddSeconds($startSecond)
# If startDate is in the future, fallback to nowif ($startDate -gt $now) { $startDate = $now.AddMinutes(-(Get-Random -Minimum 1 -Maximum 60))}
Write-Host "Generating $OrderCount events starting around: $($startDate.ToString('o'))" -ForegroundColor Cyan
$current = $startDate.ToUniversalTime()
for ($i = 1; $i -le $OrderCount; $i++) { # Generate unique order ID: ORD-MMDDHHMM-### $orderTimestamp = $current.ToString('MMddHHmm') $orderSequence = $i.ToString('D3') $orderNumber = "ORD-$orderTimestamp-$orderSequence"
$city = $cities[Get-Random -Minimum 0 -Maximum $cities.Count] $rowCount = Get-Random -Minimum $RowsMin -Maximum ($RowsMax + 1)
$rows = for ($r = 1; $r -le $rowCount; $r++) { @{ Id = $r; Amount = (Get-Random -Minimum 1 -Maximum 100) } }
$payload = @{ OrderNumber = $orderNumber; City = $city; Date = $current.ToString('o'); Rows = $rows } | ConvertTo-Json -Depth 5
# Build the LogEvent object (fields chosen to be compatible with Nodinite JSON Log Event) $logEvent = [ordered]@{ LogAgentValueId = $LogAgentValueId EndPointName = $EndPointName EndPointUri = "C:\\temp\\pickup" EndPointDirection = 0 EndPointTypeId = 60 OriginalMessageTypeName = $MessageType LogDateTime = $current.ToString('o') EventDirection = 0 ProcessingUser = "DEMO\\Generator" SequenceNo = $i EventNumber = $i LogText = "Demo order generated" ApplicationInterchangeId = $orderNumber LogStatus = 0 ProcessName = "DemoOrderProcess" ProcessingMachineName = $env:COMPUTERNAME ProcessingModuleName = "Generate-Nodinite-LogEvents.ps1" ProcessingModuleType = "DemoGenerator" ProcessingTime = (Get-Random -Minimum 10 -Maximum 300) Body = To-Base64 $payload Context = @{ OrderNumber = $orderNumber; City = $city } }
$json = $logEvent | ConvertTo-Json -Depth 10
$fileName = "LogEvent_{0}_{1}.json" -f $orderNumber, ([guid]::NewGuid()) $filePath = Join-Path -Path $OutputFolder -ChildPath $fileName
# Write UTF8 no BOM [System.IO.File]::WriteAllText($filePath, $json, [System.Text.Encoding]::UTF8)
# Advance current by a few to tens of seconds (randomized) $current = $current.AddSeconds((Get-Random -Minimum 5 -Maximum 300))
if ($i % 50 -eq 0) { Write-Host " Created $i/$OrderCount events..." -ForegroundColor Green }}
Write-Host "Done. Files written to: $OutputFolder" -ForegroundColor CyanWhat This Script Does
Section titled “What This Script Does”- PowerShell 7 features - Uses improved
ConvertTo-Json -Depthand UTF-8 encoding without BOM - Randomizes data - Each order gets a random city from 30+ options and 1-9 order rows
- Realistic timestamps - Events scattered throughout earlier today (simulates organic traffic)
- Base64 encoding - Payload JSON is automatically base64-encoded in the
Bodyfield - Context properties - Includes
OrderNumberandCityfor searchability in Log Views - Processing metadata - Sets
ProcessingTime,ProcessingMachineName, and other Log Event properties
Next steps: Place generated files in the Pickup Service input folder, or post them directly to the Log API as described in Log using REST.
Compatibility note: This script requires PowerShell 7 or later. The
#Requires -Version 7.0directive ensures the script won't run on older PowerShell versions.
Customizing the Script
Section titled “Customizing the Script”Configuration Parameters
Section titled “Configuration Parameters”The script accepts several parameters to customize the generated events:
| Parameter | Default | Description |
|---|---|---|
| OrderCount | 150 | Number of order Log Events to generate |
| OutputFolder | C:\temp\logevents |
Destination folder for the JSON Log Event files |
| RowsMin | 1 | Minimum number of order rows per event |
| RowsMax | 9 | Maximum number of order rows per event |
| LogAgentValueId | 42 | Log Agent ID (must exist in your Nodinite configuration) |
| EndPointName | INT101: Demo Log Events |
Endpoint name displayed in Log Views |
| MessageType | Demo.Order/1.0 |
Message Type for categorization |
Example Customizations
Section titled “Example Customizations”Generate 500 Events for a Specific Log Agent
Section titled “Generate 500 Events for a Specific Log Agent”pwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 500 -LogAgentValueId 123 -EndPointName "SAP Order Integration"Generate Small Events for Performance Testing
Section titled “Generate Small Events for Performance Testing”pwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 1000 -RowsMin 1 -RowsMax 3Generate Large Events for Payload Size Testing
Section titled “Generate Large Events for Payload Size Testing”pwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 100 -RowsMin 10 -RowsMax 20Notes & Tips
Section titled “Notes & Tips”- PowerShell 7 required: This script uses PowerShell 7 features. Run
pwshcommand (notpowershell) to use PowerShell 7. Verify version with$PSVersionTable.PSVersion. - Cross-platform: PowerShell 7 works on Windows, Linux, and macOS. This script runs on any platform where PowerShell 7 is installed.
- Direct API posting: To send events directly to the Log API rather than through the Pickup Service, post the JSON to
https://{host}:{port}/LogAPI/api/LogEvent. The Log API has no API key: it is either open, or it requires an OAuth 2.0 bearer token when Enable Authentication is checked in the Portal. See Log using REST for the base URL and samples. - Correlation IDs: For correlated multi-step flows (receive/send pairs), review the O2C Demo Data Script and adapt its correlation IDs.
- File naming: The script generates unique filenames with order number and GUID to prevent conflicts when re-running the script.
Related Scenarios
Section titled “Related Scenarios”Exception Logging
Section titled “Exception Logging”For generating .NET exception chains (Azure Functions, database errors, API failures), see:
- Generate Exception Log Events - PowerShell 7 script to create realistic exception chains
- View Exception Details - Learn how to use the v7 exception viewer in Log Views
- Serilog Integration - Automatic exception logging with Serilog sinks
Production Logging
Section titled “Production Logging”For implementing actual logging in applications:
- Hello World C# Sample - Step-by-step guide to logging with .NET and NuGet
- Log API Overview - Send events directly via HTTP POST
- Log using REST - Base URL, OAuth 2.0, and code samples
- Pickup Service - Configure asynchronous log event delivery
Next Steps
Section titled “ Next Steps” Generate Exception Log Events - Create realistic .NET exception chains for testing
Hello World C# Sample - Step-by-step guide to logging with .NET and NuGet
Serilog Overview - Production logging with Serilog sinks
Related Topics
Section titled “ Related Topics” JSON Log Event - Log Event JSON schema reference
Context Options - Add custom context properties
Log Status Codes - Error, warning, and success codes
Log Views - Query and filter logged events
Search Fields - Extract business data using Formula
Log Event - Understand the Log Event structure
Pickup Service - Configure asynchronous log event delivery
Log API - Send events directly via HTTP POST