Skip to content

Add structured logging sample#122

Open
jamescrosswell wants to merge 1 commit into
mainfrom
logging-sample
Open

Add structured logging sample#122
jamescrosswell wants to merge 1 commit into
mainfrom
logging-sample

Conversation

@jamescrosswell
Copy link
Copy Markdown
Collaborator

@jamescrosswell jamescrosswell commented May 22, 2026

Adds samples/send-logs.ps1 to demonstrate sending structured logs to Sentry from PowerShell, using the Sentry Logs feature exposed by the underlying sentry-dotnet SDK.

Logs are opted into via Experimental.EnableLogs = $true on the options block, then emitted with [Sentry.SentrySdk]::Logger.LogTrace/LogDebug/LogInfo/LogWarning/LogError/LogFatal. The sample also shows a templated message ({0}, {1}, ...) with structured parameters that become searchable attributes on the log record in Sentry.

A couple of PowerShell-specific notes baked into the sample:

  • The .NET Logger.LogInfo overload uses params object[], which PowerShell doesn't auto-expand — arguments are wrapped in [object[]]@(...).
  • Templates use positional {0} / {1} placeholders (matching string.Format), not named {user} style.

Closes #115

#skip-changelog

Demonstrates enabling Sentry Logs via Experimental.EnableLogs and
emitting messages at every severity level, including a templated
message with structured parameters.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 0ad0270

Comment thread samples/send-logs.ps1
Comment thread samples/send-logs.ps1
Comment on lines +42 to +44
[Sentry.SentrySdk]::Logger.LogInfo(
'User {0} ran send-logs.ps1 on {1} (PowerShell {2})',
([object[]]@($user, $host_, $psVersion)))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cases such as this - if we want to add the sample for - are worth a separate native PowerShell API

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sth like this for example: #131

vaind added a commit that referenced this pull request May 22, 2026
Mirrors the sample from PR #122 but uses the new cmdlet, including the
-Parameters and -Attributes flags. Also fixes the changelog entry to
include the PR number so Danger picks it up.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Support sending of logs with the PowerShell module

2 participants