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
Allows logging your own messages during the execution of PnP PowerShell cmdlets
14
+
15
+
## SYNTAX
16
+
17
+
### Log from file
18
+
19
+
```powershell
20
+
Write-PnPTraceLog -Path <string> [-Verbose]
21
+
```
22
+
### Log from log stream
23
+
24
+
```powershell
25
+
Write-PnPTraceLog [-Verbose]
26
+
```
27
+
28
+
## DESCRIPTION
29
+
This cmdlet allows logging of your own messages in line with the PnPTraceLog cmdlets that allow logging what happens behind the scenes of the execution of PnP PowerShell cmdlets. This allows you to inject your own custom logging along with the built in logging to get a complete and chronoligal log of the execution of the cmdlets in your scripts.
30
+
31
+
Look at [Start-PnPTraceLog](Start-PnPTraceLog.md) to see how to start logging to a file and/or to an in memory stream.
32
+
You can use [Get-PnPTraceLog](Get-PnPTraceLog.md) to read from the log file or the in memory stream.
33
+
34
+
## EXAMPLES
35
+
36
+
### EXAMPLE 1
37
+
```powershell
38
+
Write-PnPTraceLog "Hello World"
39
+
```
40
+
41
+
This logs the message "Hello World" as an informational message to the built in logging.
42
+
43
+
### EXAMPLE 2
44
+
```powershell
45
+
Write-PnPTraceLog "Hello World" -Level Warning
46
+
```
47
+
48
+
This logs the message "Hello World" as an warning message to the built in logging.
This logs the message "Hello World" as an error message to the built in logging with a source of "MyScript". The source is used to identify the cmdlet that was executed when the log was created. This is useful to identify which part of your script was executing when the log was created.
This is the most complete example. It logs the message "Hello World" as a debug message to the built in logging with a source of "MyScript", a correlation id of "5a6206a0-6c83-4446-9d1b-38c14f93cb60" and an ellapsed time of 1000 milliseconds. The correlation id is used to identify the set of operations that were executed when the log was created. The ellapsed time is used to identify how long the operation took to complete. You can provide your own measurements to define this value. If you omit the ellapsed time, the cmdlet will try to define the execution time based on the last logged entry.
63
+
64
+
## PARAMETERS
65
+
66
+
### -CorrelationId
67
+
An optional GUID as an unique identifier for the cmdlet execution. This is useful to identify which part of your script was executing when the log was created. If not provided, it will leave the value empty.
68
+
69
+
```yaml
70
+
Type: Guid
71
+
Parameter Sets: (All)
72
+
73
+
Required: False
74
+
Position: Named
75
+
Default value: None
76
+
Accept pipeline input: False
77
+
Accept wildcard characters: False
78
+
```
79
+
80
+
### -EllapsedMilliseconds
81
+
You can optionaly provide the ellapsed time in milliseconds. This is the time that was taken to execute the operation. If you omit this parameter, the cmdlet will try to define the execution time based on the last logged entry.
82
+
83
+
```yaml
84
+
Type: Long
85
+
Parameter Sets: (All)
86
+
87
+
Required: False
88
+
Position: Named
89
+
Default value: None
90
+
Accept pipeline input: False
91
+
Accept wildcard characters: False
92
+
```
93
+
94
+
### -Level
95
+
The level to log your message under. Options are: Verbose, Information, Warning, Error and Debug. It will log it both to the default PowerShell its logging equivallent such as Write-Warning, Write-Error, Write-Verbose, and to the PnPTraceLog logging. If not provided, it will default to Information.
96
+
97
+
```yaml
98
+
Type: Framework.Diagnostics.LogLevel
99
+
Parameter Sets: (All)
100
+
101
+
Required: False
102
+
Position: Named
103
+
Default value: Information
104
+
Accept pipeline input: False
105
+
Accept wildcard characters: False
106
+
```
107
+
108
+
### -Message
109
+
The message to log. This is the message that will be logged to the log file or the in memory stream.
110
+
111
+
```yaml
112
+
Type: String
113
+
Parameter Sets: (All)
114
+
115
+
Required: True
116
+
Position: Named
117
+
Default value: None
118
+
Accept pipeline input: True
119
+
Accept wildcard characters: False
120
+
```
121
+
122
+
### -Source
123
+
The source of the log. This is the source that will be logged to the log file or the in memory stream. This is useful to identify which part of your script was executing when the log was created.
124
+
125
+
```yaml
126
+
Type: String
127
+
Parameter Sets: (All)
128
+
129
+
Required: False
130
+
Position: Named
131
+
Default value: None
132
+
Accept pipeline input: False
133
+
Accept wildcard characters: False
134
+
```
135
+
136
+
### -Verbose
137
+
When provided, additional debug statements will be shown while executing the cmdlet.
138
+
139
+
```yaml
140
+
Type: SwitchParameter
141
+
Parameter Sets: (All)
142
+
143
+
Required: False
144
+
Position: Named
145
+
Default value: None
146
+
Accept pipeline input: False
147
+
Accept wildcard characters: False
148
+
```
149
+
150
+
## RELATED LINKS
151
+
152
+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
0 commit comments