Skip to content

Commit d15f226

Browse files
committed
Show readme with log description and sharing instructions
1 parent 137b788 commit d15f226

2 files changed

Lines changed: 122 additions & 8 deletions

File tree

src/lsptoolshost/logging/collectLogs.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
promptForToolArguments,
2020
DumpType,
2121
createActivityLogCapture,
22+
generateReadmeContent,
2223
} from './loggingUtils';
2324
import { runDotnetTraceInTerminal } from './profiling';
2425
import { RazorLogger } from '../../razor/src/razorLogger';
@@ -155,14 +156,25 @@ async function collectLogs(
155156
}
156157

157158
if (archiveResult.uri) {
158-
const openFolder = vscode.l10n.t('Open Folder');
159-
const result = await vscode.window.showInformationMessage(
160-
vscode.l10n.t('C# logs saved successfully.'),
161-
openFolder
162-
);
163-
if (result === openFolder) {
164-
await vscode.commands.executeCommand('revealFileInOS', archiveResult.uri);
165-
}
159+
await showReadme(selectedLogs, archiveResult.uri.fsPath);
160+
await showSuccessPopup(archiveResult.uri);
161+
}
162+
}
163+
164+
async function showReadme(selectedLogs: LogsToCollect, archivePath: string) {
165+
const readmeContent = generateReadmeContent(selectedLogs, archivePath);
166+
const document = await vscode.workspace.openTextDocument({
167+
content: readmeContent,
168+
language: 'markdown',
169+
});
170+
await vscode.commands.executeCommand('markdown.showPreview', document.uri);
171+
}
172+
173+
async function showSuccessPopup(uri: vscode.Uri) {
174+
const openFolder = vscode.l10n.t('Open Folder');
175+
const result = await vscode.window.showInformationMessage(vscode.l10n.t('C# logs saved successfully.'), openFolder);
176+
if (result === openFolder) {
177+
await vscode.commands.executeCommand('revealFileInOS', uri);
166178
}
167179
}
168180

src/lsptoolshost/logging/loggingUtils.ts

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,3 +517,105 @@ export interface LogsToCollect {
517517
memoryDump: boolean;
518518
gcDump: boolean;
519519
}
520+
521+
/**
522+
* Generate a readme.md file which describes the contents of the log archive,
523+
* warns the user about potentially sensitive information in the logs, and
524+
* provides instructions on how to share the logs with Microsoft for troubleshooting.
525+
* @param options Which additional logs were selected for collection
526+
* @param archivePath The absolute path where the archive was saved on disk
527+
*/
528+
export function generateReadmeContent(options: LogsToCollect, archivePath: string): string {
529+
const lines: string[] = [];
530+
531+
lines.push('# C# Extension Log Archive');
532+
lines.push('');
533+
lines.push(
534+
'An archive was generated by the **C# extension for Visual Studio Code** (`CSharp: Collect C# Logs` command).'
535+
);
536+
lines.push('');
537+
lines.push(`**Archive location**: [${archivePath}](${archivePath})`);
538+
lines.push('');
539+
540+
lines.push('## Contents');
541+
lines.push('');
542+
543+
lines.push('### Current Logs and Settings');
544+
lines.push('');
545+
lines.push('| File | Description |');
546+
lines.push('| --- | --- |');
547+
lines.push('| `csharp.log` | C# extension output log |');
548+
lines.push('| `csharp-lsp-trace.log` | LSP trace log between VS Code and the Roslyn language server |');
549+
lines.push('| `razor.log` | Razor language support log |');
550+
lines.push('| `csharp-settings.json` | Current C# extension settings at time of capture |');
551+
lines.push('');
552+
553+
if (options.activityLogs) {
554+
lines.push('### Record Activity');
555+
lines.push('');
556+
lines.push(
557+
'Activity logs capture live output recorded during the diagnostic session with the log level set to Trace.'
558+
);
559+
lines.push('');
560+
lines.push('| File | Description |');
561+
lines.push('| --- | --- |');
562+
lines.push('| `csharp.activity.log` | C# output captured during the recording session |');
563+
lines.push('| `csharp-lsp-trace.activity.log` | LSP trace captured during the recording session |');
564+
lines.push('| `razor.activity.log` | Razor output captured during the recording session |');
565+
lines.push('');
566+
}
567+
568+
if (options.performanceTrace) {
569+
lines.push('### Performance Trace');
570+
lines.push('');
571+
lines.push(
572+
'A `.nettrace` file captured using `dotnet-trace`. This file contains runtime events from the language server process.'
573+
);
574+
lines.push('');
575+
lines.push(
576+
'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.'
577+
);
578+
lines.push('');
579+
}
580+
581+
if (options.memoryDump) {
582+
lines.push('### Memory Dump');
583+
lines.push('');
584+
lines.push(
585+
'One or more `.dmp` files captured using `dotnet-dump`. These contain a full process memory dump of the language server.'
586+
);
587+
lines.push('');
588+
lines.push(
589+
'> **WARNING**: Memory dumps contain the full process memory and may include sensitive data such as source code, file contents, and credentials loaded in memory.'
590+
);
591+
lines.push('');
592+
}
593+
594+
if (options.gcDump) {
595+
lines.push('### GC Dump');
596+
lines.push('');
597+
lines.push(
598+
'One or more `.gcdump` files captured using `dotnet-gcdump`. These contain managed heap information from the language server.'
599+
);
600+
lines.push('');
601+
}
602+
603+
lines.push('## Sharing');
604+
lines.push('');
605+
606+
lines.push('> **WARNING**: This archive may contain sensitive information such as file paths, project names,');
607+
lines.push('> source code fragments, and other workspace-specific details. Please review the contents before');
608+
lines.push('> sharing publicly.');
609+
lines.push('');
610+
611+
lines.push(
612+
'**Publicly**: Attach this archive to your [GitHub issue](https://github.com/dotnet/vscode-csharp/issues).'
613+
);
614+
lines.push('');
615+
lines.push(
616+
'**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.'
617+
);
618+
lines.push('');
619+
620+
return lines.join('\n');
621+
}

0 commit comments

Comments
 (0)