Skip to content

Commit

Permalink
try to try and log
Browse files Browse the repository at this point in the history
  • Loading branch information
summeroff committed Mar 28, 2024
1 parent 74d96e1 commit 973a6fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
19 changes: 18 additions & 1 deletion Build-Dependencies.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,26 @@ param(
[switch] $SkipAll,
[switch] $SkipBuild,
[switch] $SkipDeps,
[switch] $SkipUnpack
[switch] $SkipUnpack,
[string] $LogFilePath = ".\build_log.txt" # Default log file path
)

# Function to log messages to both console and file
function Log-Message {
param(
[Parameter(Mandatory = $true)]
[string]$Message,
[Parameter(Mandatory = $false)]
[string]$Path = $LogFilePath
)

# Write to console
Write-Host $Message

# Append to log file
$Message | Out-File -FilePath $Path -Append -Encoding UTF8
}

Set-PSDebug -Trace 1

$ErrorActionPreference = "Stop"
Expand Down
32 changes: 16 additions & 16 deletions utils.pwsh/Setup-Target.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,26 @@ function Find-VisualStudio {

try {
$VisualStudioData = Get-CimInstance -ClassName MSFT_VSInstance -ErrorAction Stop
Write-Output "Successfully retrieved Visual Studio instance data."
Log-Message "Successfully retrieved Visual Studio instance data."
} catch {
Write-Output "Failed to retrieve Visual Studio instance data."
Write-Output "Error details: $_"
Log-Message "Failed to retrieve Visual Studio instance data."
Log-Message "Error details: $_"
if ($_.Exception.InnerException) {
Write-Output "Inner exception details: $($_.Exception.InnerException.Message)"
Log-Message "Inner exception details: $($_.Exception.InnerException.Message)"
}
# Optionally, log additional error properties
Write-Output "Exception Type: $($_.Exception.GetType().FullName)"
Write-Output "Error Message: $($_.Exception.Message)"
Write-Output "Error Category: $($_.CategoryInfo.Category)"
Write-Output "Error Target: $($_.CategoryInfo.TargetName)"
Write-Output "Error Target Type: $($_.CategoryInfo.TargetType)"
# To provide more context, you can include information about the current environment
Write-Output "PowerShell Version: $($PSVersionTable.PSVersion)"
Write-Output "OS Version: $([Environment]::OSVersion)"
# If you're interested in all loaded assemblies, which might be relevant for troubleshooting, uncomment the next line
# Write-Output "Loaded Assemblies: $([AppDomain]::CurrentDomain.GetAssemblies() | Out-String)"
# Log additional error properties
Log-Message "Exception Type: $($_.Exception.GetType().FullName)"
Log-Message "Error Message: $($_.Exception.Message)"
Log-Message "Error Category: $($_.CategoryInfo.Category)"
Log-Message "Error Target: $($_.CategoryInfo.TargetName)"
Log-Message "Error Target Type: $($_.CategoryInfo.TargetType)"
# Environmental context
Log-Message "PowerShell Version: $($PSVersionTable.PSVersion)"
Log-Message "OS Version: $([Environment]::OSVersion)"
# Uncomment if needed
# Log-Message "Loaded Assemblies: $([AppDomain]::CurrentDomain.GetAssemblies() | Out-String)"
}

# Prefer VS versions in this order:
# 1. VS2022 Release (stable)
# 2. VS2022 Preview
Expand Down

0 comments on commit 973a6fe

Please sign in to comment.