added logging to the project

This commit is contained in:
2026-03-27 12:30:30 -07:00
parent 42e20da6de
commit 989426efa0
5 changed files with 77 additions and 2 deletions

View File

@@ -12,6 +12,18 @@
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
# --- Start transcript logging ---
try {
$config = Import-PowerShellDataFile -Path (Join-Path $PSScriptRoot '..\config.psd1')
$logDir = Join-Path $config.LogPath $env:USERNAME
New-Item -ItemType Directory -Path $logDir -Force -ErrorAction SilentlyContinue | Out-Null
Start-Transcript -Path (Join-Path $logDir 'OBSReplayBuffer-Tray.log') -Append -ErrorAction Stop
} catch {
# Log path unavailable — continue without transcript
}
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Tray icon started."
function Show-Notification {
param([string]$Title, [string]$Body)
try {
@@ -46,12 +58,16 @@ $saveItem.Add_Click({
$saveItem.Enabled = $false
$saveItem.Text = 'Saving...'
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Save replay requested."
$result = & powershell.exe -ExecutionPolicy Bypass -NonInteractive -File $saveScript
if ($result -eq $true) {
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Replay saved successfully."
Show-Notification -Title 'IT Screen Recorder' -Body 'Replay saved.'
}
else {
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [ERROR] Replay save failed."
Show-Notification -Title 'IT Screen Recorder' -Body 'Could not save replay. Please contact the helpdesk.'
}
@@ -60,6 +76,7 @@ $saveItem.Add_Click({
})
$exitItem.Add_Click({
Write-Host "$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss') [INFO] Tray icon exited by user."
$tray.Visible = $false
[System.Windows.Forms.Application]::Exit()
})
@@ -74,3 +91,4 @@ $tray.ContextMenuStrip = $menu
[System.Windows.Forms.Application]::Run()
$tray.Dispose()
Stop-Transcript -ErrorAction SilentlyContinue