Skip to content

Commit 477b328

Browse files
committed
Added sample apps and updated readme/deps
1 parent a8ce5a6 commit 477b328

15 files changed

+321
-12
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,6 @@ _Pvt_Extensions
234234

235235
# FAKE - F# Make
236236
.fake/
237+
.idea/
238+
.DS_Store
239+
*.DotSettings

README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,36 @@
22

33
[![Build status](https://ci.appveyor.com/api/projects/status/bvmfe8muijhgkb9j?svg=true)](https://ci.appveyor.com/project/serilog/serilog-sinks-exceptionless)
44

5-
Serilog sink to publish to Exceptionless
65

7-
```
8-
PM> Install-Package Serilog.Sinks.Exceptionless
6+
### Getting started
7+
8+
To use the Exceptionless sink, first install the [NuGet package](https://www.nuget.org/packages/Serilog.Sinks.Exceptionless/):
9+
10+
```powershell
11+
Install-Package Serilog.Sinks.Exceptionless
912
```
1013

11-
Read the Exceptionless configuration
14+
Next, we need to ensure that Exceptionless is configured with an API Key. If you are
15+
already using Exceptionless you can skip this step.
16+
17+
The Exceptionless sink will use the default `ExceptionlessClient` client instance. This ensures
18+
that all of your Exceptionless configuration is shared with the sink and also enables logging
19+
of unhandled exceptions to Exceptionless.
20+
21+
> For advanced users who wish to configure the sink to use custom `ExceptionlessClient` instance
22+
> you can provide an API Key or `ExceptionlessClient` instance to `WriteTo.Exceptionless()`.
23+
1224
```csharp
1325
using Exceptionless;
14-
Exceptionless.ExceptionlessClient.Default.Startup();
26+
ExceptionlessClient.Default.Startup("API_KEY");
1527
```
1628

29+
Next, enable the sink using `WriteTo.Exceptionless()`
30+
1731
```csharp
1832
Log.Logger = new LoggerConfiguration()
19-
.WriteTo.Exceptionless(b => b.AddTags("ASP.NET Core Example Logger"))
33+
.WriteTo.Exceptionless(b => b.AddTags("Serilog Example"))
2034
.CreateLogger();
21-
22-
var log = Log.ForContext<HomeController>();
23-
log.Information("Info Log that also contains HttpContext request info and default tags");
2435
```
2536

2637
* [Documentation](https://github.com/serilog/serilog/wiki)

Serilog.Sinks.Exceptionless.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{E9D1B5
1515
EndProject
1616
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Serilog.Sinks.Exceptionless", "src\Serilog.Sinks.Exceptionless\Serilog.Sinks.Exceptionless.csproj", "{E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}"
1717
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample", "sample", "{C63B899E-A823-48E4-B29D-A26014911A9D}"
19+
EndProject
20+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleDemo", "sample\ConsoleDemo\ConsoleDemo.csproj", "{411E131D-34F5-4B51-A217-B4FD6E2E01B4}"
21+
EndProject
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleWeb", "sample\SampleWeb\SampleWeb.csproj", "{2637C70D-5166-473F-91FD-C5312310466D}"
23+
EndProject
1824
Global
1925
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2026
Debug|Any CPU = Debug|Any CPU
@@ -25,11 +31,21 @@ Global
2531
{E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}.Debug|Any CPU.Build.0 = Debug|Any CPU
2632
{E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}.Release|Any CPU.ActiveCfg = Release|Any CPU
2733
{E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F}.Release|Any CPU.Build.0 = Release|Any CPU
34+
{411E131D-34F5-4B51-A217-B4FD6E2E01B4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
35+
{411E131D-34F5-4B51-A217-B4FD6E2E01B4}.Debug|Any CPU.Build.0 = Debug|Any CPU
36+
{411E131D-34F5-4B51-A217-B4FD6E2E01B4}.Release|Any CPU.ActiveCfg = Release|Any CPU
37+
{411E131D-34F5-4B51-A217-B4FD6E2E01B4}.Release|Any CPU.Build.0 = Release|Any CPU
38+
{2637C70D-5166-473F-91FD-C5312310466D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
39+
{2637C70D-5166-473F-91FD-C5312310466D}.Debug|Any CPU.Build.0 = Debug|Any CPU
40+
{2637C70D-5166-473F-91FD-C5312310466D}.Release|Any CPU.ActiveCfg = Release|Any CPU
41+
{2637C70D-5166-473F-91FD-C5312310466D}.Release|Any CPU.Build.0 = Release|Any CPU
2842
EndGlobalSection
2943
GlobalSection(SolutionProperties) = preSolution
3044
HideSolutionNode = FALSE
3145
EndGlobalSection
3246
GlobalSection(NestedProjects) = preSolution
3347
{E85ABEC7-9B4C-432C-9A04-AC5BE9205D9F} = {037440DE-440B-4129-9F7A-09B42D00397E}
48+
{411E131D-34F5-4B51-A217-B4FD6E2E01B4} = {C63B899E-A823-48E4-B29D-A26014911A9D}
49+
{2637C70D-5166-473F-91FD-C5312310466D} = {C63B899E-A823-48E4-B29D-A26014911A9D}
3450
EndGlobalSection
3551
EndGlobal

sample/ConsoleDemo/ConsoleDemo.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFrameworks>net452;net50</TargetFrameworks>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<ProjectReference Include="..\..\src\Serilog.Sinks.Exceptionless\Serilog.Sinks.Exceptionless.csproj" />
8+
</ItemGroup>
9+
<ItemGroup>
10+
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
11+
</ItemGroup>
12+
</Project>

sample/ConsoleDemo/Program.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Serilog;
2+
using System;
3+
using System.Threading;
4+
using Exceptionless;
5+
using Serilog.Sinks.SystemConsole.Themes;
6+
7+
namespace ConsoleDemo
8+
{
9+
public class Program
10+
{
11+
public static void Main()
12+
{
13+
ExceptionlessClient.Default.Startup("API_KEY");
14+
15+
Log.Logger = new LoggerConfiguration()
16+
.MinimumLevel.Verbose()
17+
.WriteTo.Console(theme: AnsiConsoleTheme.Code)
18+
.WriteTo.Exceptionless(c => c.AddTags("Serilog Sample"))
19+
.CreateLogger();
20+
21+
try
22+
{
23+
Log.Debug("Getting started");
24+
Log.Information("Hello {Name} from thread {ThreadId}", Environment.GetEnvironmentVariable("USERNAME"), Thread.CurrentThread.ManagedThreadId);
25+
Log.Warning("No coins remain at position {@Position}", new { Lat = 25, Long = 134 });
26+
27+
Fail();
28+
}
29+
catch (Exception ex)
30+
{
31+
Log.Error(ex, "Something went wrong");
32+
}
33+
34+
Log.CloseAndFlush();
35+
}
36+
37+
private static void Fail()
38+
{
39+
throw new DivideByZeroException();
40+
}
41+
}
42+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Security.Claims;
3+
using System.Text.Encodings.Web;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Authentication;
6+
using Microsoft.Extensions.Logging;
7+
using Microsoft.Extensions.Options;
8+
9+
namespace SampleWeb.Authentication
10+
{
11+
public class TestAuthenticationHandler : AuthenticationHandler<AuthenticationSchemeOptions>
12+
{
13+
public TestAuthenticationHandler(IOptionsMonitor<AuthenticationSchemeOptions> options,
14+
ILoggerFactory logger, UrlEncoder encoder, ISystemClock clock)
15+
: base(options, logger, encoder, clock)
16+
{
17+
}
18+
19+
protected override Task<AuthenticateResult> HandleAuthenticateAsync()
20+
{
21+
var claims = new[]
22+
{
23+
new Claim(ClaimTypes.Name, "Test user"),
24+
new Claim(ClaimTypes.NameIdentifier, Guid.NewGuid().ToString())
25+
};
26+
var identity = new ClaimsIdentity(claims, "Test");
27+
var principal = new ClaimsPrincipal(identity);
28+
var ticket = new AuthenticationTicket(principal, "Test");
29+
return Task.FromResult(AuthenticateResult.Success(ticket));
30+
}
31+
}
32+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.Extensions.Logging;
4+
5+
namespace SampleWeb.Controllers
6+
{
7+
[ApiController]
8+
[Route("[controller]")]
9+
public class ValuesController : ControllerBase
10+
{
11+
private readonly ILogger<ValuesController> _logger;
12+
13+
public ValuesController(ILogger<ValuesController> logger)
14+
{
15+
_logger = logger;
16+
}
17+
18+
[HttpGet]
19+
public string Get()
20+
{
21+
_logger.LogInformation("Get was called");
22+
return $"[{Activity.Current?.Id}] {User.Identity?.Name}";
23+
}
24+
}
25+
}

sample/SampleWeb/Program.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
using Microsoft.AspNetCore.Hosting;
6+
using Microsoft.Extensions.Configuration;
7+
using Microsoft.Extensions.Hosting;
8+
using Microsoft.Extensions.Logging;
9+
using Serilog;
10+
11+
namespace SampleWeb
12+
{
13+
public class Program
14+
{
15+
public static void Main(string[] args)
16+
{
17+
CreateHostBuilder(args).Build().Run();
18+
}
19+
20+
public static IHostBuilder CreateHostBuilder(string[] args)
21+
{
22+
return Host.CreateDefaultBuilder(args)
23+
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>())
24+
.UseSerilog((hostingContext, services, loggerConfiguration) => loggerConfiguration
25+
.ReadFrom.Configuration(hostingContext.Configuration)
26+
.Enrich.FromLogContext()
27+
.WriteTo.Debug()
28+
.WriteTo.Console()
29+
.WriteTo.Exceptionless()
30+
);
31+
}
32+
}
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"iisSettings": {
4+
"windowsAuthentication": false,
5+
"anonymousAuthentication": true,
6+
"iisExpress": {
7+
"applicationUrl": "http://localhost:59081",
8+
"sslPort": 44340
9+
}
10+
},
11+
"profiles": {
12+
"IIS Express": {
13+
"commandName": "IISExpress",
14+
"launchBrowser": true,
15+
"launchUrl": "values",
16+
"environmentVariables": {
17+
"ASPNETCORE_ENVIRONMENT": "Development"
18+
}
19+
},
20+
"SampleWeb": {
21+
"commandName": "Project",
22+
"dotnetRunMessages": "true",
23+
"launchBrowser": true,
24+
"launchUrl": "values",
25+
"applicationUrl": "https://localhost:5001;http://localhost:5000",
26+
"environmentVariables": {
27+
"ASPNETCORE_ENVIRONMENT": "Development"
28+
}
29+
}
30+
}
31+
}

sample/SampleWeb/SampleWeb.csproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
<PropertyGroup>
3+
<TargetFramework>net5.0</TargetFramework>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<PackageReference Include="Exceptionless.AspNetCore" Version="4.5.0" />
8+
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
9+
</ItemGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\..\src\Serilog.Sinks.Exceptionless\Serilog.Sinks.Exceptionless.csproj" />
13+
</ItemGroup>
14+
</Project>

0 commit comments

Comments
 (0)