- 4 minutes to read

FAQ — Generate a batch of Nodinite JSON Log Events (PowerShell)

This FAQ shows a PowerShell script to generate a batch of Nodinite JSON Log Event files suitable for use with the Pickup Log Events Service (or for demos/load tests).

Overview:

  • Generates one JSON LogEvent file per order
  • Randomizes city and order rows
  • Each LogEvent has a distinct LogDateTime "some time ago today" (no date parameter required)
  • Files are written UTF-8 (no BOM)

Usage (quick)

Open PowerShell 7+ 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.

Script: Generate-Nodinite-LogEvents.ps1

Save this file next to your documentation or in a demo folder. It uses deterministic pseudo-random values (no external dependencies).

<#
Generates Nodinite-style LogEvent JSON files for demo/load-testing.
- PowerShell 7+ recommended
- Each file contains a single LogEvent object
#>
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++) {
    $orderId = 10000 + $i
    $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 = @{ OrderId = $orderId; 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 = "ORD-$orderId"
        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 = "ORD-$orderId"; City = $city }
    }

    $json = $logEvent | ConvertTo-Json -Depth 10

    $fileName = "LogEvent_ORD{0}_{1}.json" -f $orderId, ([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

Notes & tips:

  • For correlated multi-step flows (receive/send pairs) review Generate-O2C-Demo-Data-REFACTORED.ps1 in the Troubleshooting\Demo folder and adapt the deterministic correlation IDs and step templates.
  • If you want to send these events directly to Log API rather than to Pickup, wrap the JSON with an HTTP POST using your API key and the Log API endpoint.

If you'd like, I can commit this file (Troubleshooting/FAQ - bre - Hello World - .NET Sample.md) to the repository and update the original Getting started page to link to the new sample location. Let me know if you want multi-event (BPM-like) flows instead of single-event-per-order files.