-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.ps1
34 lines (33 loc) · 1.33 KB
/
Log.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function Log-Error([Exception] $ex, [string]$label) {
$logTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff"
$mtx = New-Object System.Threading.Mutex($false, "TestMutex")
if ($mtx.WaitOne(1000)) {
if (!$LogFilePath) {
$scriptPath = Split-Path -Parent $script:MyInvocation.MyCommand.Path
$LogFilePath = Join-Path -Path $scriptPath -ChildPath Install.log
}
Write-Output "$logTime [Exception] $label" | Where-Object {$LogFilePath -ne $null} | Out-File -FilePath $LogFilePath -Append
Write-Output " $ex" | Where-Object {$LogFilePath -ne $null} | Out-File $LogFilePath -Append
} else {
Write-Host "Log file is locked!"
Write-Host "$logTime [Exception] $label"
Write-Host " $ex"
}
$mtx.ReleaseMutex()
}
function Log([string]$level, [string]$label) {
$logTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss.fff"
$mtx = New-Object System.Threading.Mutex($false, "TestMutex")
if ($mtx.WaitOne(1000)) {
if (!$LogFilePath) {
$scriptPath = Split-Path -Parent $script:MyInvocation.MyCommand.Path
$LogFilePath = Join-Path -Path $scriptPath -ChildPath Install.log
}
Write-Output "$logTime [$level] $label" | Where-Object {$LogFilePath -ne $null} | Out-File -FilePath $LogFilePath -Append
Write-Host "$logTime [$level] $label"
} else {
Write-Host "Log file is locked!"
Write-Host "$logTime [$level] $label"
}
$mtx.ReleaseMutex()
}