You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: OZOLogger/OZOLogger.psm1
+9-3Lines changed: 9 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,15 @@
1
1
ClassOZOLogger {
2
2
# PROPERTIES
3
3
[Boolean] $writeOutput=$true
4
+
Hidden [String] $scriptName=$null
4
5
# METHODS
6
+
# Constructor method
7
+
OZOLogger($ScriptName) {
8
+
$this.scriptName=$ScriptName
9
+
}
5
10
# Write method
6
11
[Void] Write([String]$Message,[String]$Level) {
12
+
# Set properties
7
13
# Set default value for Id
8
14
[Int32] $Id=0000
9
15
# Declare valid Levels
@@ -18,11 +24,11 @@ Class OZOLogger {
18
24
}
19
25
# Try to write to the One Zero One provider
20
26
Try {
21
-
New-WinEvent-ProviderName "One Zero One"-Id $Id-Payload (Split-Path-Path $PSCommandPath-Leaf),$Message-ErrorAction Stop
27
+
New-WinEvent-ProviderName "One Zero One"-Id $Id-Payload $this.scriptName,$Message-ErrorAction Stop
22
28
# Success
23
29
} Catch {
24
30
# Failure; write to the Microsoft-Windows-PowerShell provider instead using EventID 4100
25
-
New-WinEvent-ProviderName "Microsoft-Windows-PowerShell"-Id 4100(Split-Path-Path $PSCommandPath-Leaf),'Please install the "One Zero One" Windows Event Log provider to support the optimal use of the OZOLogger module. See https://github.com/onezeroone-dev/OZO-Windows-Event-Log-Provider-Setup/blob/main/README.md for more information.',$Message-ErrorAction SilentlyContinue
31
+
New-WinEvent-ProviderName "Microsoft-Windows-PowerShell"-Id 4100$this.scriptName,'Please install the "One Zero One" Windows Event Log provider to support the optimal use of the OZOLogger module. See https://github.com/onezeroone-dev/OZO-Windows-Event-Log-Provider-Setup/blob/main/README.md for more information.',$Message-ErrorAction SilentlyContinue
26
32
}
27
33
# Determine if writeOutput is true AND session is user-interactive
28
34
If ($this.writeOutput-eq$true-And [Environment]::UserInteractive -eq$true) {
0 commit comments