Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
36fde27
feat: Serilog sink no longer initializes the SDK
jamescrosswell Sep 14, 2026
5385388
Accept API verifier changes
getsentry-bot Sep 14, 2026
f7f48a5
Merge remote-tracking branch 'origin/version7' into feat/no-init-from…
jamescrosswell Sep 14, 2026
9f8ec8c
Merge remote-tracking branch 'origin/feat/no-init-from-logging-5245' …
jamescrosswell Sep 14, 2026
c72c26e
Tweak comments in the samples
jamescrosswell Sep 17, 2026
cafeb7b
feat: NLog target no longer initializes the SDK
jamescrosswell Sep 17, 2026
19db652
Tweaked wording
jamescrosswell Sep 17, 2026
489d7ce
feat: NLog target flushes using the SDK's FlushTimeout
jamescrosswell Sep 17, 2026
0aada87
docs: drop unused Sentry settings from the Serilog sample appsettings
jamescrosswell Sep 21, 2026
5acfa5e
fix(serilog): make the UseSerilog warning check atomic
jamescrosswell Sep 21, 2026
d038075
Merge remote-tracking branch 'origin/feat/no-init-from-logging-5245' …
jamescrosswell Sep 22, 2026
3307c30
refactor: the Serilog sink no longer sets the SDK name
jamescrosswell Sep 22, 2026
bbc1166
Merge branch 'feat/no-init-from-logging-5245' into feat/no-init-from-…
jamescrosswell Sep 22, 2026
62dad84
refactor: the NLog target no longer sets the SDK name
jamescrosswell Sep 22, 2026
72d27f9
feat(serilog): configuring a DSN on the sink now fails with a migrati…
ric-oliv Sep 22, 2026
9d27112
test(serilog): pin the DSN tombstone against Serilog.Settings.Configu…
jamescrosswell Sep 22, 2026
f6039d3
Merge remote-tracking branch 'origin/feat/no-init-from-logging-5245' …
jamescrosswell Sep 22, 2026
ab2bb85
feat(nlog): configuring a DSN on the target now fails with a migratio…
jamescrosswell Sep 22, 2026
ed73567
docs(serilog): reword the DSN migration error
jamescrosswell Sep 22, 2026
6517170
Merge remote-tracking branch 'origin/feat/no-init-from-logging-5245' …
jamescrosswell Sep 22, 2026
5ab9e8f
docs(nlog): reword the DSN migration error to match Serilog
jamescrosswell Sep 22, 2026
a1bf334
fix(serilog): the Sentry sink registers the Serilog scope event proce…
ric-oliv Sep 23, 2026
6c8c4d9
Merge remote-tracking branch 'origin/feat/no-init-from-logging-5245' …
jamescrosswell Sep 23, 2026
7b88c80
fix(serilog): register the scope event processor atomically
jamescrosswell Sep 23, 2026
f76ac32
Merge remote-tracking branch 'origin/feat/no-init-from-logging-5245' …
jamescrosswell Sep 23, 2026
53f4144
refactor(serilog): use the Lock shim for the registration lock
jamescrosswell Sep 23, 2026
0925c1d
Merge remote-tracking branch 'origin/feat/no-init-from-logging-5245' …
jamescrosswell Sep 23, 2026
bbf2ffd
Merge remote-tracking branch 'origin/version7' into feat/no-init-from…
jamescrosswell Sep 23, 2026
a8a1ea9
Merge remote-tracking branch 'origin/feat/no-init-from-logging-5245' …
jamescrosswell Sep 23, 2026
fbbaa39
docs: samples are exempt from the no-comments rule
jamescrosswell Sep 23, 2026
5f4f1d1
Apply suggestion from @jamescrosswell
jamescrosswell Sep 23, 2026
2925072
feat(serilog): warn at runtime when the sink drops events because Sen…
jamescrosswell Sep 28, 2026
5ff4ec6
Merge remote-tracking branch 'origin/feat/no-init-from-logging-5245' …
jamescrosswell Sep 28, 2026
0a57f71
feat(nlog): warn at runtime when the target drops events because Sent…
jamescrosswell Sep 28, 2026
7d92ca3
Merge remote-tracking branch 'origin/version7' into feat/no-init-from…
jamescrosswell Sep 29, 2026
ae9cdda
fix(nlog): report a stale dsn and accept initializeSdk=false (#5652)
ric-oliv Sep 30, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions samples/Sentry.Samples.NLog/NLog.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
<targets>
<target name="logconsole" xsi:type="ColoredConsole" />

<!-- You can also add a `dsn` property to the following target (with the DSN of your Sentry project):
See Program.cs for the DSN used in the code-only example-->

<!-- This only configures the Sentry target. Sentry itself is initialised in Program.cs -->
<target xsi:type="Sentry" name="sentry"
environment="Development"
includeEventProperties="True"
layout="${message}"
breadcrumbLayout="${message}"
Expand All @@ -24,13 +21,6 @@
includeEventPropertiesAsTags="True"
minimumEventLevel="Error">

<!-- Advanced options can be configured here-->
<options
attachStacktrace="true"
sendDefaultPii="true"
shutdownTimeoutSeconds="5"
/>

<!--Optionally add any desired additional Tags that will be sent with every message -->
<tag name="exception" layout="${exception:format=shorttype}" includeEmptyValue="false" />

Expand Down
28 changes: 14 additions & 14 deletions samples/Sentry.Samples.NLog/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ public static class Program

private static void Main()
{
// Initialise the Sentry SDK
using var _ = SentrySdk.Init(options =>
{
#if !SENTRY_DSN_DEFINED_IN_ENV
// A DSN is required. You can set here in code, or you can set it in the SENTRY_DSN environment variable.
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
options.Dsn = SamplesShared.Dsn;
#endif
options.AttachStacktrace = true;
options.SendDefaultPii = true; // Send Personal Identifiable information like the username of the user logged in to the device
});

try
{
// You can configure your logger using a configuration file:
Expand Down Expand Up @@ -97,28 +109,18 @@ private static void UsingNLogConfigFile()

private static void UsingCodeConfiguration()
{
// Other overloads exist, for example, configure the SDK with only the DSN or no parameters at all.
// Configure NLog to send logs to Sentry
var config = LogManager.Configuration = new LoggingConfiguration();
_ = config
.AddSentry(options =>
{
#if !SENTRY_DSN_DEFINED_IN_ENV
// A DSN is required. You can set here in code, in the SENTRY_DSN environment variable or in the
// NLog.config file.
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
options.Dsn = SamplesShared.Dsn;
#endif
options.Layout = "${message}";
options.BreadcrumbLayout = "${logger}: ${message}"; // Optionally specify a separate format for breadcrumbs

options.MinimumBreadcrumbLevel = LogLevel.Debug; // Debug and higher are stored as breadcrumbs (default is Info)
options.MinimumEventLevel = LogLevel.Error; // Error and higher is sent as event (default is Error)

options.AttachStacktrace = true;
options.SendDefaultPii = true; // Send Personal Identifiable information like the username of the user logged in to the device
options.MinimumEventLevel = LogLevel.Error; // Error and higher are sent as events (default is Error)

options.IncludeEventDataOnBreadcrumbs = true; // Optionally include event properties with breadcrumbs
options.ShutdownTimeoutSeconds = 5;

//Optionally specify user properties via NLog (here using MappedDiagnosticsLogicalContext as an example)
options.User = new SentryNLogUser
Expand All @@ -134,8 +136,6 @@ private static void UsingCodeConfiguration()
};

options.AddTag("logger", "${logger}"); // Send the logger name as a tag

// Other configuration
});

config.AddTarget(new DebuggerTarget("debugger"));
Expand Down
26 changes: 3 additions & 23 deletions samples/Sentry.Samples.NLog/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

This is a simple console application that demonstrates how you can add Sentry to your application using NLog.

This project attempts to sample the integration by using code only and also via the configuration file.
In both cases **you need to add your own DSN** so you can see the events sent in your Sentry project.
This project demonstrates configuring Sentry and NLog via code and configuration.
The Sentry target configures NLog to send logs to Sentry. The Sentry SDK itself is initialised via the call to `SentrySdk.Init`
in `Program.cs`, so **you need to add your own DSN** there to see the events sent in your Sentry project.

You can get your [Sentry DSN at sentry.io](https://sentry.io).
Make sure to add it to both `NLog.config` and `Program.cs` in this directory.

## Configuration of NLog.config
The following options are available for the NLog Sentry Target:

```xml
<target xsi:type="Sentry" name="sentry"
dsn="https://123@sentry.io/456"
environment="${environment:cached=true:ASPNETCORE_ENVIRONMENT}"
release="${assembly-version:cached=true:type=File}"
layout="${message}"
includeEventProperties="True"
includeMdlc="False"
Expand All @@ -25,17 +22,9 @@ The following options are available for the NLog Sentry Target:
ignoreEventsWithNoException="False"
includeEventDataOnBreadcrumbs="False"
includeEventPropertiesAsTags="True"
initializeSdk="True"
flushTimeoutSeconds="15"
>
<tag name="exception" layout="${exception:format=shorttype}" includeEmptyValue="false" /><!-- Repeatable SentryEvent Tags -->
<contextproperty name="threadid" layout="${threadid}" includeEmptyValue="true" /> <!-- Repeatable SentryEvent Data -->
<!-- Advanced options can be configured here-->
<options
sendDefaultPii="False"
isEnvironmentUser="True"
attachStacktrace="False"
/>
<!-- Optionally specify user properties via NLog (here using MappedDiagnosticsLogicalContext as an example) -->
<user
id="${mdlc:item=id}"
Expand All @@ -48,10 +37,6 @@ The following options are available for the NLog Sentry Target:
</target>
```

* **dsn** - Sentry Data Source Name Address. See also https://sentry.io
* **initializeSdk** - Whether the NLog target should initialize the Sentry SDK (Using Dsn). Default: _True_
* **environment** - Application Environment sent to Sentry
* **release** - Application Release Version sent to Sentry
* **layout** - NLog Layout for rendering SentryEvent message. Default: _${message}_
* **includeEventProperties** - Include LogEvent properties as Data on SentryEvent. Default: _True_
* **includeEventPropertiesAsTags** - Include LogEvent properties as extra Tags on SentryEvent. Default: _False_
Expand All @@ -61,17 +46,12 @@ The following options are available for the NLog Sentry Target:
* **minimumEventLevel** - Send NLog LogEvents as SentryEvent when matching severity (or worse). Default: _Error_
* **minimumBreadcrumbLevel** - Send NLog LogEvents as Breadcrumbs when matching severity (or worse). Default: _Info_
* **ignoreEventsWithNoException** - Ignore NLog LogEvents without an exception. Default: _False_
* **flushTimeoutSeconds** - Flush timeout in seconds before aborting flush to Sentry. Default: _15_
* **user**
* **id**
* **username**
* **email**
* **ipAddress**
* **other** - Any arbitrary key-value pairs to be included as properties for a user on every event.
* **options**
* **sendDefaultPii** - Whether to include default Personal Identifiable information (UserName / IP-Address). Default: _False_
* **isEnvironmentUser** - Lookup Environment.User if having enabled **sendDefaultPii**. Default: _True_
* **attachStacktrace** - Whether to send the stack trace of a event captured without an exception. Default: _False_

There is filtering logic in the Sentry Target that is usually handled by NLog Logging Rules and Filters.
Mostly because the same Sentry Target is writing both breadcrumbs and actual SentryEvents.
Expand Down
67 changes: 27 additions & 40 deletions src/Sentry.NLog/ConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,66 +12,58 @@ public static class ConfigurationExtensions
// Internal for testability
internal const string DefaultTargetName = "sentry";

internal const string ObsoleteDsnOverload =
"The Sentry target no longer initializes the SDK, so a DSN can no longer be supplied to it. " +
"Initialize Sentry with SentrySdk.Init (or UseSentry via one of the integrations), and remove 'dsn', " +
"'initializeSdk' and any other core SDK settings from the target configuration.";

/// <summary>
/// Adds a target for Sentry to the NLog configuration.
/// Not supported. The Sentry target no longer initializes the SDK.
/// </summary>
/// <remarks>
/// If DSN is not set, the SDK will look for an environment variable called SENTRY_DSN. If nothing is
/// found, SDK is disabled.
/// </remarks>
/// <param name="configuration">The NLog configuration.</param>
/// <param name="dsn">No longer supported.</param>
/// <param name="optionsConfig">An optional action for configuring the Sentry target options.</param>
/// <returns>The configuration.</returns>
/// <returns>Never returns.</returns>
/// <exception cref="NotSupportedException">Always.</exception>
[Obsolete(ObsoleteDsnOverload, error: true)]
public static LoggingConfiguration AddSentry(
this LoggingConfiguration configuration,
string? dsn,
Action<SentryNLogOptions>? optionsConfig = null)
{
// Not to throw on code that ignores nullability warnings.
if (configuration.IsNull())
{
return configuration!;
}

return configuration.AddSentry(null, DefaultTargetName, optionsConfig);
}
=> throw new NotSupportedException(ObsoleteDsnOverload);

/// <summary>
/// Adds a target for Sentry to the NLog configuration.
/// Not supported. The Sentry target no longer initializes the SDK.
/// </summary>
/// <param name="configuration">The NLog configuration.</param>
/// <param name="dsn">
/// The sentry DSN. If DSN is not set, the SDK will look for an environment variable called SENTRY_DSN.
/// If nothing is found, SDK is disabled.
/// </param>
/// <param name="dsn">No longer supported.</param>
/// <param name="targetName">The name to give the new target.</param>
/// <param name="optionsConfig">An optional action for configuring the Sentry target options.</param>
/// <returns>The configuration.</returns>
/// <returns>Never returns.</returns>
/// <exception cref="NotSupportedException">Always.</exception>
[Obsolete(ObsoleteDsnOverload, error: true)]
public static LoggingConfiguration AddSentry(
this LoggingConfiguration configuration,
string? dsn,
string targetName,
Action<SentryNLogOptions>? optionsConfig = null)
{
// Not to throw on code that ignores nullability warnings.
if (configuration.IsNull())
{
return configuration!;
}

return configuration.AddSentry(dsn, DefaultTargetName, optionsConfig);
}
=> throw new NotSupportedException(ObsoleteDsnOverload);

/// <summary>
/// Adds a target for Sentry to the NLog configuration.
/// </summary>
/// <remarks>
/// This doesn't initialise Sentry. Initialise Sentry separately, using <c>SentrySdk.Init</c> or another Sentry
/// integration (such as ASP.NET Core or MAUI).
/// </remarks>
/// <param name="configuration">The NLog configuration.</param>
/// <param name="dsn">The sentry DSN.</param>
/// <param name="targetName">The name to give the new target.</param>
/// <param name="optionsConfig">An optional action for configuring the Sentry target options.</param>
/// <param name="targetName">The name to give the new target.</param>
/// <returns>The configuration.</returns>
public static LoggingConfiguration AddSentry(
this LoggingConfiguration configuration,
string? dsn,
string targetName,
Action<SentryNLogOptions>? optionsConfig = null)
Action<SentryNLogOptions>? optionsConfig = null,
string targetName = DefaultTargetName)
{
// Not to throw on code that ignores nullability warnings.
if (configuration.IsNull())
Expand All @@ -95,11 +87,6 @@ public static LoggingConfiguration AddSentry(
Layout = "${message}",
};

if (dsn != null && string.IsNullOrWhiteSpace(options.Dsn))
{
options.Dsn = dsn;
}

configuration.AddTarget(targetName, target);

configuration.AddRuleForAllLevels(targetName);
Expand Down
12 changes: 0 additions & 12 deletions src/Sentry.NLog/Constants.cs

This file was deleted.

58 changes: 0 additions & 58 deletions src/Sentry.NLog/NLogDiagnosticLogger.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/Sentry.NLog/Sentry.NLog.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<Using Include="Sentry.NLog" />
<Using Include="Sentry.Extensibility" />
<Using Include="Sentry.Infrastructure" />
<Using Include="Sentry.Internal" />
<Using Include="Sentry.Reflection" />
</ItemGroup>

Expand Down
Loading
Loading