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
Tip
Use cases: Demo environments, load testing, training sessions, performance testing, and testing Nodinite logging infrastructure.
Info
PowerShell 7 required: This script uses PowerShell 7 features like improved JSON handling, better UTF-8 support, and cross-platform compatibility. Install PowerShell 7 if you haven't already.
Need exception testing? For generating .NET exception chains (Azure Functions, database errors), see Generate Exception Log Events.
Jump to section: Understanding Log Event Generation | Batch Generation | Script Details
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 Logging Service, or sent directly via Log API.
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
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)
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
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
<#
.SYNOPSIS
Generates Nodinite-style LogEvent JSON files for demo/load-testing.
.DESCRIPTION
This 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 OrderCount
Number of order events to generate (default: 150)
.PARAMETER OutputFolder
Destination folder for generated JSON files (default: C:\temp\logevents)
.EXAMPLE
pwsh .\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 exists
if (-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 text
function 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 now
if ($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 Cyan
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 use Log API to send them directly via HTTP POST.
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
Configuration Parameters
The script accepts several parameters to customize the generated events:
| Parameter | Default | Description |
|---|---|---|
| OrderCount | 150 | Number of order events to generate |
| OutputFolder | C:\temp\logevents |
Destination folder for JSON 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
Generate 500 events for a specific Log Agent:
pwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 500 -LogAgentValueId 123 -EndPointName "SAP Order Integration"
Generate small events (1-3 rows each) for performance testing:
pwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 1000 -RowsMin 1 -RowsMax 3
Generate large events (10-20 rows each) for payload size testing:
pwsh .\Generate-Nodinite-LogEvents.ps1 -OrderCount 100 -RowsMin 10 -RowsMax 20
Tip
Tip: For correlated multi-step flows (receive/send pairs), review
Generate-O2C-Demo-Data-REFACTORED.ps1in theTroubleshooting\Demofolder and adapt the deterministic correlation IDs and step templates.
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: If you want to send events directly to Log API rather than to Pickup Service, wrap the JSON with an HTTP POST using your API key and the Log API endpoint.
- Correlation IDs: For correlated multi-step flows (receive/send pairs), review
Generate-O2C-Demo-Data-REFACTORED.ps1in theTroubleshooting\Demofolder and adapt the deterministic correlation IDs. - File naming: The script generates unique filenames with order number and GUID to prevent conflicts when re-running the script.
Related Scenarios
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
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
- Pickup Service - Configure asynchronous log event delivery
Next Step
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
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