I'm looking for a lightweight way to collect syslog data temporarily, preferably something that can run on Windows without needing installation. The main goal is to just dump the syslog input into a file. Any suggestions?
1 Answer
You can use PowerShell to set up a listener that captures syslog data and saves it to a file. Here's a quick script you can try:
```powershell
$port = 514
$logfile = "C:Tempsyslog_capture.log"
$logdir = Split-Path $logfile
if (!(Test-Path $logdir)) { New-Item -ItemType Directory -Path $logdir | Out-Null }
$udp = New-Object System.Net.Sockets.UdpClient($port)
Write-Host "Listening on UDP port $port... Logging to $logfile"
while ($true)
{
$remote = New-Object System.Net.IPEndPoint([System.Net.IPAddress]::Any, 0)
$bytes = $udp.Receive([ref]$remote)
$message = [System.Text.Encoding]::UTF8.GetString($bytes)
$line = "[$($remote.Address):$($remote.Port)] $message"
Write-Host $line
Add-Content -Path $logfile -Value $line
}
```
Give it a shot!
That looks like exactly what I need. Thank you!