Skip to content

Commit 8c9aceb

Browse files
committed
Added and updated documentation
1 parent 698576f commit 8c9aceb

8 files changed

+190
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
6060
- Added `Set-PnPSiteDocumentIdPrefix` which allows changing of the document id prefix on a site collection [#4765](https://github.com/pnp/powershell/pull/4765)
6161
- Added `Get-PnPMicrosoft365Roadmap` which allows retrieval of the Microsoft 365 Roadmap items [#4764](https://github.com/pnp/powershell/pull/4764)
6262
- Added `-Name` parameter to `Add-PnPApplicationCustomizer` cmdlet to allow for specifying the name of the application customizer [#4767](https://github.com/pnp/powershell/pull/4767)
63+
- Added `Get-PnPTraceLog` cmdlet which allows reading from the detailed in memory logs of the PnP PowerShell cmdlet execution
6364

6465
### Changed
6566

documentation/Clear-PnPTraceLog.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
Module Name: PnP.PowerShell
3+
title: Clear-PnPTraceLog
4+
schema: 2.0.0
5+
applicable: SharePoint Online
6+
external help file: PnP.PowerShell.dll-Help.xml
7+
online version: https://pnp.github.io/powershell/cmdlets/Clear-PnPTraceLog.html
8+
---
9+
10+
# Clear-PnPTraceLog
11+
12+
## SYNOPSIS
13+
Clears the log stream in memory
14+
15+
## SYNTAX
16+
17+
```powershell
18+
Clear-PnPTraceLog [-Verbose]
19+
```
20+
21+
## DESCRIPTION
22+
This clears the in memory stored log stream which was started with the [Start-PnPTraceLog -WriteToLogstream](Start-PnPTraceLog.md) cmdlet. It will not clear the log file if one was specified.
23+
24+
## EXAMPLES
25+
26+
### EXAMPLE 1
27+
```powershell
28+
Clear-PnPTraceLog
29+
```
30+
31+
This clears the in memory stored log stream
32+
33+
## PARAMETERS
34+
35+
### -Verbose
36+
When provided, additional debug statements will be shown while executing the cmdlet.
37+
38+
```yaml
39+
Type: SwitchParameter
40+
Parameter Sets: (All)
41+
42+
Required: False
43+
Position: Named
44+
Default value: None
45+
Accept pipeline input: False
46+
Accept wildcard characters: False
47+
```
48+
49+
## RELATED LINKS
50+
51+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

documentation/Get-PnPTraceLog.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
Module Name: PnP.PowerShell
3+
title: Get-PnPTraceLog
4+
schema: 2.0.0
5+
applicable: SharePoint Online
6+
external help file: PnP.PowerShell.dll-Help.xml
7+
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPTraceLog.html
8+
---
9+
10+
# Get-PnPTraceLog
11+
12+
## SYNOPSIS
13+
Returns logged messages during the execution of PnP PowerShell cmdlets
14+
15+
## SYNTAX
16+
17+
### Log from file
18+
19+
```powershell
20+
Get-PnPTraceLog -Path <string> [-Verbose]
21+
```
22+
### Log from log stream
23+
24+
```powershell
25+
Get-PnPTraceLog [-Verbose]
26+
```
27+
28+
## DESCRIPTION
29+
This cmdlet returns the logged messages during the execution of PnP PowerShell cmdlets. It can return the messages from an in memory log stream or from a file. You can use [Start-PnPTraceLog](Start-PnPTraceLog.md) to start logging to a file and/or to an in memory stream.
30+
31+
## EXAMPLES
32+
33+
### EXAMPLE 1
34+
```powershell
35+
Get-PnPTraceLog
36+
```
37+
38+
This returns all items in the in memory stored log stream
39+
40+
### EXAMPLE 2
41+
```powershell
42+
Get-PnPTraceLog -Path "C:\temp\log.txt"
43+
```
44+
45+
This returns all items from the log file stored at the provided location
46+
47+
### EXAMPLE 3
48+
```powershell
49+
Get-PnPTraceLog | Where-Object { $_.Level -eq "Error" }
50+
```
51+
52+
This returns only logged items from the in memory stored log stream that have a level of "Error"
53+
54+
### EXAMPLE 4
55+
```powershell
56+
Get-PnPTraceLog | Where-Object { $_.CorrelationId -eq "5a6206a0-6c83-4446-9d1b-38c14f93cb60" }
57+
```
58+
59+
This returns only logged items from the in memory stored log stream that happened during the execution of a PnP PowerShell cmdlet with the provided correlation id. This is useful to find out what happened during the execution of a specific cmdlet. Mind that the correlation id is an unique identifier for the cmdlet execution assigned by PnP PowerShell and is not the same as the correlation id of a SharePoint operation.
60+
61+
## PARAMETERS
62+
63+
### -Path
64+
The path to the log file. If not provided, the cmdlet will return the in memory log stream.
65+
66+
```yaml
67+
Type: String
68+
Parameter Sets: Log from file
69+
70+
Required: True
71+
Position: Named
72+
Default value: None
73+
Accept pipeline input: True
74+
Accept wildcard characters: False
75+
```
76+
77+
### -Verbose
78+
When provided, additional debug statements will be shown while executing the cmdlet.
79+
80+
```yaml
81+
Type: SwitchParameter
82+
Parameter Sets: (All)
83+
84+
Required: False
85+
Position: Named
86+
Default value: None
87+
Accept pipeline input: False
88+
Accept wildcard characters: False
89+
```
90+
91+
## RELATED LINKS
92+
93+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

documentation/Start-PnPTraceLog.md

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,26 @@ Starts log tracing
1515
## SYNTAX
1616

1717
```powershell
18-
Start-PnPTraceLog [-Path <String>] [-Level <LogLevel>] [-AutoFlush <Boolean>] [-WriteToConsole <SwitchParameter>]
18+
Start-PnPTraceLog [-Path <String>] [-Level <LogLevel>] [-AutoFlush <Boolean>] [-WriteToConsole <SwitchParameter>] [-WriteToLogStream <SwitchParameter>]
1919
```
2020

21-
2221
## DESCRIPTION
2322
Starts .NET tracelogging. Many cmdlets output detailed trace information when executed. Turn on the trace log with this cmdlet, optionally specify the level. By default the level is set to 'Information', but you will receive more detail by setting the level to 'Debug'.
2423

24+
You can look at the logged data using [Get-PnPTraceLog](Get-PnPTraceLog.md).
25+
26+
The logged data contains the following information in the following order:
27+
28+
- Timestamp
29+
- Source
30+
- Thread ID
31+
- Log level
32+
- Message
33+
- Elapsed time in milliseconds since the last log entry for the same cmdlet execution
34+
- Correlation ID which is an unique identifier per executed cmdlet so you can filter the log for everything logged during a specific cmdlet execution
35+
36+
Beware that the logged data can be quite verbose, especially when the level is set to 'Debug'. When logging in memory, it can take up a lot of memory. When logging to a file, it can take up a lot of disk space. So be careful when using this in production environments and only use it when you need to troubleshoot something or are aware of the consequences.
37+
2538
## EXAMPLES
2639

2740
### EXAMPLE 1
@@ -38,12 +51,19 @@ Start-PnPTraceLog -Path ./TraceOutput.txt -Level Debug
3851

3952
This turns on trace logging to the file 'TraceOutput.txt' and will capture all events.
4053

54+
### EXAMPLE 3
55+
```powershell
56+
Start-PnPTraceLog -WriteToConsole -WriteToLogStream -Level Debug
57+
```
58+
59+
This turns on trace logging to the console and in memory stream in which you are running your PowerShell script and will capture all events.
60+
4161
### EXAMPLE 3
4262
```powershell
4363
Start-PnPTraceLog -WriteToConsole -Level Debug
4464
```
4565

46-
This turns on trace logging to console in which you are running your PowerShell script and will capture all events.
66+
This turns on trace logging to the console in which you are running your PowerShell script and will capture all events.
4767

4868
## PARAMETERS
4969

@@ -104,6 +124,20 @@ Accept pipeline input: False
104124
Accept wildcard characters: False
105125
```
106126
127+
### -WriteToLogStream
128+
Write the trace log to the in memory stream. Use [Get-PnPTraceLog](Get-PnPTraceLog.md) to read the log stream.
129+
130+
```yaml
131+
Type: SwitchParameter
132+
Parameter Sets: (All)
133+
134+
Required: False
135+
Position: Named
136+
Default value: False
137+
Accept pipeline input: False
138+
Accept wildcard characters: False
139+
```
140+
107141
## RELATED LINKS
108142
109143
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

documentation/Stop-PnPTraceLog.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Stop-PnPTraceLog
2020

2121

2222
## DESCRIPTION
23-
Stops .NET tracelogging. Many cmdlets output detailed trace information when executed. Turn on the trace log with Start-PnPTraceLog, optionally specify the level. By default the level is set to 'Information', but you will receive more detail by setting the level to 'Debug'.
23+
Stops PnP PowerShell tracelogging. Turn on the trace log with [Start-PnPTraceLog](Start-PnPTraceLog.md). Look at the logged data using [Get-PnPTraceLog](Get-PnPTraceLog.md).
2424

2525
## EXAMPLES
2626

@@ -33,5 +33,4 @@ This turns off trace logging
3333

3434
## RELATED LINKS
3535

36-
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
37-
36+
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

src/Commands/Base/BasePSCmdlet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class BasePSCmdlet : PSCmdlet
2121
/// </summary>
2222
protected override void BeginProcessing()
2323
{
24-
LogDebug("Cmdlet execution started");
24+
LogDebug($"Cmdlet execution started for {MyInvocation.MyCommand.Name}");
2525
base.BeginProcessing();
2626

2727
CheckForDeprecationAttributes();
@@ -67,7 +67,7 @@ protected override void ProcessRecord()
6767
protected override void EndProcessing()
6868
{
6969
base.EndProcessing();
70-
LogDebug("Cmdlet execution done");
70+
LogDebug($"Cmdlet execution done for {MyInvocation.MyCommand.Name}");
7171
}
7272

7373
/// <summary>

src/Commands/Base/ClearTraceLog.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ protected override void ProcessRecord()
1212
{
1313
if (Trace.Listeners[LogStreamListener.DefaultListenerName] is not LogStreamListener logStreamListener)
1414
{
15-
LogWarning("Log stream listener named {LogStreamListener.DefaultLogStreamListenerName} not found. No entries cleared.");
15+
LogWarning($"Log stream listener named {LogStreamListener.DefaultListenerName} not found. No entries cleared.");
1616
}
1717
else
1818
{

src/Commands/Base/ConnectOnline.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,12 +407,12 @@ protected void Connect(ref CancellationToken cancellationToken)
407407
try
408408
{
409409
newConnection.Context.ExecuteQueryRetry();
410-
LogDebug($"Site at {Url} exists");
410+
LogInformational($"Site at {Url} exists");
411411
}
412412
catch (System.Net.WebException e) when (e.Message.Contains("404"))
413413
{
414-
LogDebug($"Site at {Url} does not exist");
415-
throw new PSInvalidOperationException($"The specified site {Url} does not exist", e);
414+
LogError($"Site at {Url} does not exist");
415+
//throw new PSInvalidOperationException($"The specified site {Url} does not exist", e);
416416
}
417417
catch (TargetInvocationException tex)
418418
{

0 commit comments

Comments
 (0)