Skip to content

Commit 0adb30d

Browse files
alievertzAndy Lievertz
andauthored
Corrected how the running script name is determined; v1.0.1 (#2)
Co-authored-by: Andy Lievertz <[email protected]>
1 parent 5e60062 commit 0adb30d

File tree

5 files changed

+13
-6
lines changed

5 files changed

+13
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
|Date|Version|Comment|
44
|----|-------|-------|
5-
|2024-Dec-13|1.0.0|Initial release|
5+
|2024-Dec-15|1.0.1|Corrected how the running script name is determined.|
6+
|2024-Dec-13|1.0.0|Initial release.|

OZOLogger-test.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Import-Module -Name (Join-Path -Path (Split-Path -Path $PSCommandPath -Parent) -ChildPath "OZOLogger")
1+
Import-Module -Name (Join-Path -Path $PSScriptRoot -ChildPath "OZOLogger")
22

33
$ozoLoggerObject = New-OZOLogger
44
#$ozoLoggerObject.SetConsoleOutput("off")

OZOLogger/OZOLogger.psd1

0 Bytes
Binary file not shown.

OZOLogger/OZOLogger.psm1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
Class OZOLogger {
22
# PROPERTIES
33
[Boolean] $writeOutput = $true
4+
Hidden [String] $scriptName = $null
45
# METHODS
6+
# Constructor method
7+
OZOLogger($ScriptName) {
8+
$this.scriptName = $ScriptName
9+
}
510
# Write method
611
[Void] Write([String]$Message,[String]$Level) {
12+
# Set properties
713
# Set default value for Id
814
[Int32] $Id = 0000
915
# Declare valid Levels
@@ -18,11 +24,11 @@ Class OZOLogger {
1824
}
1925
# Try to write to the One Zero One provider
2026
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
2228
# Success
2329
} Catch {
2430
# 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
2632
}
2733
# Determine if writeOutput is true AND session is user-interactive
2834
If ($this.writeOutput -eq $true -And [Environment]::UserInteractive -eq $true) {
@@ -49,7 +55,7 @@ Class OZOLogger {
4955
}
5056

5157
Function New-OZOLogger() {
52-
return [OZOLogger]::new()
58+
return [OZOLogger]::new((Split-Path -Path $MyInvocation.ScriptName -Leaf))
5359
}
5460

5561
Export-ModuleMember New-OZOLogger

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ $ozoLoggerObject.Write("This is a test message.","Information")
3535

3636
## Classes
3737
### OZOLogger
38-
Calling the `New-OZOLogger` function returns an object of the `OZOLogger` class. This class contains one property and two methods.
38+
Calling the `New-OZOLogger` function returns an object of the `OZOLogger` class. This class contains one public property and two public methods.
3939
#### Properties
4040

4141
|Property|Type|Description|

0 commit comments

Comments
 (0)