Skip to content

Commit 60e2301

Browse files
committed
Show readme with log description and sharing instructions
1 parent 017404a commit 60e2301

2 files changed

Lines changed: 126 additions & 9 deletions

File tree

src/lsptoolshost/logging/collectLogs.ts

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
verifyOrAcquireDotnetTool,
2020
DumpType,
2121
createActivityLogCapture,
22+
generateReadmeContent,
2223
} from './loggingUtils';
2324
import { runDotnetTraceInTerminal } from './profiling';
2425
import { RazorLogger } from '../../razor/src/razorLogger';
@@ -142,15 +143,29 @@ async function collectLogs(
142143
}),
143144
{ modal: true }
144145
);
145-
} else if (archiveResult.uri) {
146-
const openFolder = vscode.l10n.t('Open Folder');
147-
const result = await vscode.window.showInformationMessage(
148-
vscode.l10n.t('C# logs saved successfully.'),
149-
openFolder
150-
);
151-
if (result === openFolder) {
152-
await vscode.commands.executeCommand('revealFileInOS', archiveResult.uri);
153-
}
146+
return;
147+
}
148+
149+
if (archiveResult.uri) {
150+
await showReadme(selectedLogs, archiveResult.uri.fsPath);
151+
await showSuccessPopup(archiveResult.uri);
152+
}
153+
}
154+
155+
async function showReadme(selectedLogs: LogsToCollect, archivePath: string) {
156+
const readmeContent = generateReadmeContent(selectedLogs, archivePath);
157+
const document = await vscode.workspace.openTextDocument({
158+
content: readmeContent,
159+
language: 'markdown',
160+
});
161+
await vscode.commands.executeCommand('markdown.showPreview', document.uri);
162+
}
163+
164+
async function showSuccessPopup(uri: vscode.Uri) {
165+
const openFolder = vscode.l10n.t('Open Folder');
166+
const result = await vscode.window.showInformationMessage(vscode.l10n.t('C# logs saved successfully.'), openFolder);
167+
if (result === openFolder) {
168+
await vscode.commands.executeCommand('revealFileInOS', uri);
154169
}
155170
}
156171

src/lsptoolshost/logging/loggingUtils.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,3 +575,105 @@ export async function createActivityLogCapture(
575575
},
576576
};
577577
}
578+
579+
/**
580+
* Generate a readme.md file which describes the contents of the log archive,
581+
* warns the user about potentially sensitive information in the logs, and
582+
* provides instructions on how to share the logs with Microsoft for troubleshooting.
583+
* @param options Which additional logs were selected for collection
584+
* @param archivePath The absolute path where the archive was saved on disk
585+
*/
586+
export function generateReadmeContent(options: LogsToCollect, archivePath: string): string {
587+
const lines: string[] = [];
588+
589+
lines.push('# C# Extension Log Archive');
590+
lines.push('');
591+
lines.push(
592+
'An archive was generated by the **C# extension for Visual Studio Code** (`CSharp: Collect C# Logs` command).'
593+
);
594+
lines.push('');
595+
lines.push(`**Archive location**: [${archivePath}](${archivePath})`);
596+
lines.push('');
597+
598+
lines.push('## Contents');
599+
lines.push('');
600+
601+
lines.push('### Current Logs and Settings');
602+
lines.push('');
603+
lines.push('| File | Description |');
604+
lines.push('| --- | --- |');
605+
lines.push('| `csharp.log` | C# extension output log |');
606+
lines.push('| `csharp-lsp-trace.log` | LSP trace log between VS Code and the Roslyn language server |');
607+
lines.push('| `razor.log` | Razor language support log |');
608+
lines.push('| `csharp-settings.json` | Current C# extension settings at time of capture |');
609+
lines.push('');
610+
611+
if (options.activityLogs) {
612+
lines.push('### Record Activity');
613+
lines.push('');
614+
lines.push(
615+
'Activity logs capture live output recorded during the diagnostic session with the log level set to Trace.'
616+
);
617+
lines.push('');
618+
lines.push('| File | Description |');
619+
lines.push('| --- | --- |');
620+
lines.push('| `csharp.activity.log` | C# output captured during the recording session |');
621+
lines.push('| `csharp-lsp-trace.activity.log` | LSP trace captured during the recording session |');
622+
lines.push('| `razor.activity.log` | Razor output captured during the recording session |');
623+
lines.push('');
624+
}
625+
626+
if (options.performanceTrace) {
627+
lines.push('### Performance Trace');
628+
lines.push('');
629+
lines.push(
630+
'A `.nettrace` file captured using `dotnet-trace`. This file contains runtime events from the language server process.'
631+
);
632+
lines.push('');
633+
lines.push(
634+
'You can view this file using [PerfView](https://github.com/microsoft/perfview), [dotnet-trace convert](https://learn.microsoft.com/dotnet/core/diagnostics/dotnet-trace#dotnet-trace-convert), or Visual Studio.'
635+
);
636+
lines.push('');
637+
}
638+
639+
if (options.memoryDump) {
640+
lines.push('### Memory Dump');
641+
lines.push('');
642+
lines.push(
643+
'One or more `.dmp` files captured using `dotnet-dump`. These contain a full process memory dump of the language server.'
644+
);
645+
lines.push('');
646+
lines.push(
647+
'> **WARNING**: Memory dumps contain the full process memory and may include sensitive data such as source code, file contents, and credentials loaded in memory.'
648+
);
649+
lines.push('');
650+
}
651+
652+
if (options.gcDump) {
653+
lines.push('### GC Dump');
654+
lines.push('');
655+
lines.push(
656+
'One or more `.gcdump` files captured using `dotnet-gcdump`. These contain managed heap information from the language server.'
657+
);
658+
lines.push('');
659+
}
660+
661+
lines.push('## Sharing');
662+
lines.push('');
663+
664+
lines.push('> **WARNING**: This archive may contain sensitive information such as file paths, project names,');
665+
lines.push('> source code fragments, and other workspace-specific details. Please review the contents before');
666+
lines.push('> sharing publicly.');
667+
lines.push('');
668+
669+
lines.push(
670+
'**Publicly**: Attach this archive to your [GitHub issue](https://github.com/dotnet/vscode-csharp/issues).'
671+
);
672+
lines.push('');
673+
lines.push(
674+
'**Privately**: If the archive contains sensitive information, upload it via the [Developer Community](https://developercommunity.visualstudio.com/dotnet/report) page and reference your GitHub issue in the description.'
675+
);
676+
lines.push('');
677+
678+
return lines.join('\n');
679+
}

0 commit comments

Comments
 (0)