@@ -35,39 +35,6 @@ function Enable-CippConsoleLogging {
3535 ' Information'
3636 }
3737
38- # Helper function to send log to Application Insights
39- $global :SendCippConsoleLog = {
40- param ([string ]$Message , [string ]$Level )
41-
42- if ($global :TelemetryClient ) {
43- try {
44- # Map level names to numeric values for comparison
45- $levelMap = @ {
46- ' Debug' = 0
47- ' Verbose' = 1
48- ' Information' = 2
49- ' Warning' = 3
50- ' Error' = 4
51- }
52-
53- $currentLevelValue = $levelMap [$Level ]
54- $minLevelValue = $levelMap [$global :CippConsoleLogMinLevel ]
55-
56- # Check if this level should be logged
57- if ($currentLevelValue -ge $minLevelValue ) {
58- $props = New-Object ' System.Collections.Generic.Dictionary[string,string]'
59- $props [' Message' ] = $Message
60- $props [' Level' ] = $Level
61- $props [' Timestamp' ] = (Get-Date ).ToString(' o' )
62-
63- $global :TelemetryClient.TrackEvent (' CIPP.ConsoleLog' , $props , $null )
64- }
65- } catch {
66- # Silently fail to avoid infinite loops
67- }
68- }
69- }
70-
7138 # Override Write-Information
7239 function global :Write-Information {
7340 [CmdletBinding ()]
@@ -77,9 +44,9 @@ function Enable-CippConsoleLogging {
7744 [string []]$Tags
7845 )
7946
80- # Send to telemetry if MessageData is string or can be converted to string and is not empty, null, or whitespace
47+ # Send to telemetry
8148 if ($MessageData -and -not [string ]::IsNullOrWhiteSpace(($MessageData | Out-String ).Trim())) {
82- & $ global :SendCippConsoleLog - Message ($MessageData | Out-String ).Trim() - Level ' Information'
49+ Send-CippConsoleLog - Message ($MessageData | Out-String ).Trim() - Level ' Information'
8350 }
8451
8552 # Call original function
@@ -94,9 +61,9 @@ function Enable-CippConsoleLogging {
9461 [string ]$Message
9562 )
9663
97- # Send to telemetry if Message is not empty, null, or whitespace
64+ # Send to telemetry
9865 if ($Message -and -not [string ]::IsNullOrWhiteSpace($Message )) {
99- & $ global :SendCippConsoleLog - Message $Message - Level ' Warning'
66+ Send-CippConsoleLog - Message $Message - Level ' Warning'
10067 }
10168
10269 # Call original function
@@ -128,7 +95,7 @@ function Enable-CippConsoleLogging {
12895 else { ' Unknown error' }
12996
13097 if ($errorMessage -and -not [string ]::IsNullOrWhiteSpace($errorMessage )) {
131- & $ global :SendCippConsoleLog - Message $errorMessage - Level ' Error'
98+ Send-CippConsoleLog - Message $errorMessage - Level ' Error'
13299 }
133100
134101 # Call original function
@@ -145,7 +112,7 @@ function Enable-CippConsoleLogging {
145112
146113 # Send to telemetry
147114 if ($Message -and -not [string ]::IsNullOrWhiteSpace($Message )) {
148- & $ global :SendCippConsoleLog - Message $Message - Level ' Verbose'
115+ Send-CippConsoleLog - Message $Message - Level ' Verbose'
149116 }
150117
151118 # Call original function
@@ -162,7 +129,7 @@ function Enable-CippConsoleLogging {
162129
163130 # Send to telemetry
164131 if ($Message -and -not [string ]::IsNullOrWhiteSpace($Message )) {
165- & $ global :SendCippConsoleLog - Message $Message - Level ' Debug'
132+ Send-CippConsoleLog - Message $Message - Level ' Debug'
166133 }
167134
168135 # Call original function
@@ -184,7 +151,7 @@ function Enable-CippConsoleLogging {
184151 # Send to telemetry
185152 $message = if ($Object ) { ($Object | Out-String ).Trim() } else { ' ' }
186153 if ($message -and -not [string ]::IsNullOrWhiteSpace($message )) {
187- & $ global :SendCippConsoleLog - Message $message - Level ' Information'
154+ Send-CippConsoleLog - Message $message - Level ' Information'
188155 }
189156
190157 # Call original function
0 commit comments