Skip to content

Commit eb400e4

Browse files
committed
ref: readme and format nits
1 parent 57163c1 commit eb400e4

File tree

10 files changed

+61
-15
lines changed

10 files changed

+61
-15
lines changed

.assets/nlog-sentry.png

394 KB
Loading

samples/Sentry.Samples.NLog/NLog.config

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88

99
<targets>
1010
<target name="logconsole" xsi:type="ColoredConsole" />
11+
12+
<!-- REPLACE THE FOLLOWING DSN WITH YOUR OWN:
13+
See Program.cs for the DSN used in the code-only example-->
14+
1115
<target xsi:type="Sentry" name="sentry"
1216
dsn="https://[email protected]/1188141"
1317
layout="${message}"
@@ -26,7 +30,6 @@
2630
<includeEventDataOnBreadcrumbs>true</includeEventDataOnBreadcrumbs>
2731
</options>
2832

29-
3033
<!--Add any desired additional tags that will be sent with every message -->
3134
<tag name="logger" layout="${logger}" />
3235
</target>

samples/Sentry.Samples.NLog/Program.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
using System;
2-
32
using NLog;
43
using NLog.Config;
54
using NLog.Targets;
65

76
// ReSharper disable ConvertToConstant.Local
8-
97
namespace Sentry.Samples.NLog
108
{
119
public static class Program
1210
{
11+
// Modify the configuration file NLog.config to affect 'UsingNLogConfigFile'
12+
13+
// DSN used by the example: 'UsingCodeConfiguration'.
14+
// #### ADD YOUR DSN HERE:
15+
private static string DsnSample = "https://[email protected]/1188141";
16+
1317
private static void Main(string[] args)
1418
{
1519
try
@@ -90,7 +94,7 @@ private static void UsingCodeConfiguration()
9094

9195
// If DSN is not set, the SDK will look for an environment variable called SENTRY_DSN. If
9296
// nothing is found, SDK is disabled.
93-
o.Dsn = new Dsn("https://[email protected]/1188141");
97+
o.Dsn = new Dsn(DsnSample);
9498

9599
o.AttachStacktrace = true;
96100
o.SendDefaultPii = true; // Send Personal Identifiable information like the username of the user logged in to the device
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Sample integration of NLog with Sentry
2+
3+
This is a simple console application that demonstrates how you can add Sentry to your application using NLog.
4+
5+
This project attempts to sample the integration by using code only and also via the configuration file.
6+
In both cases **you need to add your own DSN** so you can see the events sent in your Sentry project.
7+
8+
You can get your [Sentry DSN at sentry.io](https://sentry.io).
9+
Make sure to add it to both `NLog.config` and `Program.cs` in this directory.
10+
11+
## Running this sample
12+
13+
Now you're ready to run the code.
14+
You can run this sample with Visual Studio, or via the command line.
15+
16+
With the .NET Core SDK:
17+
18+
```sh
19+
λ dotnet run
20+
15:34 $ dotnet run
21+
2019-05-13 15:34:30.7319|TRACE|Sentry.Samples.NLog.Program|Verbose message which is not sent.
22+
2019-05-13 15:34:30.7716|DEBUG|Sentry.Samples.NLog.Program|Debug message stored as breadcrumb.
23+
2019-05-13 15:34:30.7782|ERROR|Sentry.Samples.NLog.Program|Some event that includes the previous breadcrumbs. mood = "happy that my error is reported"
24+
2019-05-13 15:34:30.8547|INFO|Sentry.Samples.NLog.Program|Dividing 10 by 0
25+
2019-05-13 15:34:30.8567|WARN|Sentry.Samples.NLog.Program|a is 0
26+
2019-05-13 15:34:30.8586|FATAL|Sentry.Samples.NLog.Program|Error: with exception. { title = compound data object, wowFactor = 11, errorReported = True }
27+
2019-05-13 15:34:32.1986|TRACE|Sentry.Samples.NLog.Program|Verbose message which is not sent.
28+
2019-05-13 15:34:32.1997|DEBUG|Sentry.Samples.NLog.Program|Debug message stored as breadcrumb.
29+
2019-05-13 15:34:32.1997|ERROR|Sentry.Samples.NLog.Program|Some event that includes the previous breadcrumbs. mood = "happy that my error is reported"
30+
2019-05-13 15:34:32.2005|INFO|Sentry.Samples.NLog.Program|Dividing 10 by 0
31+
2019-05-13 15:34:32.2005|WARN|Sentry.Samples.NLog.Program|a is 0
32+
2019-05-13 15:34:32.2010|FATAL|Sentry.Samples.NLog.Program|Error: with exception. { title = compound data object, wowFactor = 11, errorReported = True }
33+
```
34+
35+
![Sample event in Sentry](.assets/nlog-sentry.png)
36+
37+
**Please refer to the main SDK [documentation for more details](https://getsentry.github.io/sentry-dotnet/).**

samples/Sentry.Samples.NLog/Sentry.Samples.NLog.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
5-
<TargetFramework>net462</TargetFramework>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
66
</PropertyGroup>
77

88
<ItemGroup>
@@ -17,5 +17,4 @@
1717
</None>
1818
</ItemGroup>
1919

20-
2120
</Project>

src/Sentry.NLog/ConfigurationExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static LoggingConfiguration AddSentry(this LoggingConfiguration configura
3434
/// Adds a target for Sentry to the NLog configuration.
3535
/// </summary>
3636
/// <param name="configuration">The NLog configuration.</param>
37-
/// <param name="dsn">
37+
/// <param name="dsn">
3838
/// The sentry DSN. If DSN is not set, the SDK will look for an environment variable called SENTRY_DSN.
3939
/// If nothing is found, SDK is disabled.
4040
/// </param>
@@ -64,7 +64,6 @@ public static LoggingConfiguration AddSentry(this LoggingConfiguration configura
6464

6565
optionsConfig?.Invoke(options);
6666

67-
6867
Target.Register<SentryTarget>("Sentry");
6968

7069
var target = new SentryTarget(options)
@@ -95,6 +94,5 @@ public static void AddTag(this SentryNLogOptions options, string name, Layout la
9594
{
9695
options.Tags.Add(new TargetPropertyWithContext(name, layout));
9796
}
98-
9997
}
10098
}

src/Sentry.NLog/HelperExtensions.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
// ReSharper disable LoopCanBePartlyConvertedToQuery
55
// ReSharper disable LoopCanBeConvertedToQuery
6-
76
namespace Sentry.NLog
87
{
98
internal static class HelperExtensions
@@ -24,7 +23,9 @@ internal static IEnumerable<KeyValuePair<TKey, TValue>> ToKeyValuePairs<TSource,
2423
}
2524
}
2625

27-
internal static IEnumerable<KeyValuePair<TKey, TNewValue>> MapValues<TKey, TValue, TNewValue>(this IEnumerable<KeyValuePair<TKey, TValue>> source, Func<TValue,TNewValue> valueSelector)
26+
internal static IEnumerable<KeyValuePair<TKey, TNewValue>> MapValues<TKey, TValue, TNewValue>(
27+
this IEnumerable<KeyValuePair<TKey, TValue>> source,
28+
Func<TValue,TNewValue> valueSelector)
2829
{
2930
if (source is null)
3031
{

src/Sentry.NLog/SentryNLogOptions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ public int ShutdownTimeoutSeconds
7575
[NLogConfigurationIgnoreProperty] // Configure this directly on the target in XML config.
7676
public IList<TargetPropertyWithContext> Tags { get; } = new List<TargetPropertyWithContext>();
7777

78+
/// <summary>
79+
/// Whether the NLog integration should initialize the SDK.
80+
/// </summary>
81+
/// <remarks>
82+
/// By default, if a DSN is provided to the NLog integration it will initialize the SDK.
83+
/// This might be not ideal when using multiple integrations in case you want another one doing the Init.
84+
/// </remarks>
7885
[Advanced]
7986
public bool InitializeSdk { get; set; } = true;
8087
}

src/Sentry.NLog/SentryTarget.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,5 @@ private IEnumerable<KeyValuePair<string, object>> GetLoggingEventProperties(LogE
244244

245245
return logEvent.Properties.ToKeyValuePairs(x => x.Key.ToString(), x => x.Value);
246246
}
247-
248247
}
249248
}

test/Sentry.NLog.Tests/Sentry.NLog.Tests.csproj

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
<PropertyGroup>
44
<TargetFrameworks>netcoreapp2.1;net461</TargetFrameworks>
5-
</PropertyGroup>
5+
</PropertyGroup>
66
<ItemGroup>
77
<ProjectReference Include="..\..\src\Sentry.NLog\Sentry.NLog.csproj" />
88
<ProjectReference Include="..\Sentry.Testing\Sentry.Testing.csproj" />
99
</ItemGroup>
1010

11-
12-
1311
</Project>

0 commit comments

Comments
 (0)