-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #553 from MindscapeHQ/ph/ms-logger
Add MS Logger support
- Loading branch information
Showing
38 changed files
with
1,037 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
indent_size = 2 | ||
|
||
[*.cs] | ||
# https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0290 | ||
csharp_style_prefer_primary_constructors = false | ||
dotnet_diagnostic.IDE0290.severity = none | ||
|
||
# https://www.jetbrains.com/help/rider/ConvertToPrimaryConstructor.html | ||
resharper_convert_to_primary_constructor_highlighting = none | ||
|
||
# Ensure if statements always use braces | ||
csharp_prefer_braces = true:error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Mindscape.Raygun4Net.AspNetCore.Tests/Mindscape.Raygun4Net.AspNetCore.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
Mindscape.Raygun4Net.AspNetCore/Builders/RequestDataBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
|
||
namespace Mindscape.Raygun4Net.AspNetCore.Builders; | ||
|
||
public class RequestDataBuilder : IMessageBuilder | ||
{ | ||
private readonly IHttpContextAccessor _httpContextAccessor; | ||
private readonly RaygunSettings _settings; | ||
|
||
public RequestDataBuilder(IHttpContextAccessor httpContextAccessor, RaygunSettings settings) | ||
{ | ||
_httpContextAccessor = httpContextAccessor; | ||
_settings = settings; | ||
} | ||
|
||
public async Task<RaygunMessage> Apply(RaygunMessage message, Exception exception) | ||
{ | ||
var ctx = _httpContextAccessor.HttpContext; | ||
|
||
message.Details.Request = await RaygunAspNetCoreRequestMessageBuilder.Build(ctx, _settings); | ||
message.Details.Response = await RaygunAspNetCoreResponseMessageBuilder.Build(ctx, _settings); | ||
|
||
return message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
Mindscape.Raygun4Net.Extensions.Logging/Mindscape.Raygun4Net.Extensions.Logging.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;net6.0;net7.0;net8.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<AssemblyOriginatorKeyFile>..\Raygun.snk</AssemblyOriginatorKeyFile> | ||
<SignAssembly>true</SignAssembly> | ||
<IsPackable>true</IsPackable> | ||
<DebugType>embedded</DebugType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<None Include="README.md" Pack="true" PackagePath="\" /> | ||
<None Include="..\LICENSE" Pack="true" PackagePath="\" /> | ||
<None Include="..\128x128-transparent.png" Pack="true" PackagePath="\" /> | ||
</ItemGroup> | ||
|
||
<PropertyGroup> | ||
<Description>.NET / .NETStandard - library for targeting .NET applications</Description> | ||
<PackageId>Mindscape.Raygun4Net.Extensions.Logging</PackageId> | ||
<PackageLicenseFile>LICENSE</PackageLicenseFile> | ||
<PackageIconUrl>https://app.raygun.com/Content/Images/nuget-icon.png</PackageIconUrl> | ||
<PackageIcon>128x128-transparent.png</PackageIcon> | ||
<PackageReadmeFile>README.md</PackageReadmeFile> | ||
<PackageReleaseNotes>https://github.com/MindscapeHQ/raygun4net/blob/master/CHANGE-LOG.md</PackageReleaseNotes> | ||
<PackageTags>crash;exception-handling;exception-reporting;exception-handler;unhandled-exceptions;debugging;debug;bug;bugs;exceptions;error;errors;crash-reporting;logging;mslogger</PackageTags> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Mindscape.Raygun4Net.NetCore.Common\Mindscape.Raygun4Net.NetCore.Common.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Mindscape.Raygun4Net.Extensions.Logging | ||
|
||
This package provides a logging provider for the Raygun service. It allows you to send log messages to Raygun, | ||
where they can be viewed and managed in the Raygun dashboard. | ||
|
||
## Installation | ||
|
||
Install the **Mindscape.Raygun4Net.Extensions.Logging** NuGet package into your project. You can either use the below dotnet CLI command, or the NuGet management GUI in the IDE you use. | ||
|
||
```csharp | ||
dotnet add package Mindscape.Raygun4Net.Extensions.Logging | ||
``` | ||
|
||
You will need to install the **Mindscape.Raygun4Net** package as well, if you haven't already. | ||
|
||
```csharp | ||
// If you're using it in an ASP.NET Core application: | ||
dotnet add package Mindscape.Raygun4Net.AspNetCore | ||
|
||
// If you're using it in a .NET Core service application: | ||
dotnet add package Mindscape.Raygun4Net.NetCore | ||
``` | ||
|
||
## Usage | ||
|
||
Add the Raygun provider to the logging configuration in your `Program.cs` or `Startup.cs` file. | ||
|
||
### ASP.NET Core Application | ||
|
||
```csharp | ||
using Mindscape.Raygun4Net.AspNetCore; | ||
using Mindscape.Raygun4Net.Extensions.Logging; | ||
|
||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
// Registers the Raygun Client for AspNetCore | ||
builder.Services.AddRaygun(settings => | ||
{ | ||
settings.ApiKey = "*your api key*"; | ||
}); | ||
|
||
// (Optional) Registers the Raygun User Provider | ||
builder.Services.AddRaygunUserProvider(); | ||
|
||
// Registers the Raygun Logger for use in MS Logger | ||
builder.Logging.AddRaygunLogger(); | ||
|
||
var app = builder.Build(); | ||
``` | ||
|
||
### .NET Core Service Application | ||
|
||
```csharp | ||
using Mindscape.Raygun4Net.Extensions.Logging; | ||
using Mindscape.Raygun4Net.NetCore; | ||
|
||
var builder = Host.CreateApplicationBuilder(args); | ||
|
||
// Registers the Raygun Client for NetCore | ||
builder.Services.AddRaygun(options => | ||
{ | ||
options.ApiKey = "*your api key*"; | ||
}); | ||
|
||
// Registers the Raygun Logger for use in MS Logger | ||
builder.Logging.AddRaygunLogger(); | ||
|
||
var host = builder.Build(); | ||
``` | ||
|
||
## Configuration | ||
|
||
When registering the Raygun provider, you can configure it with the following options: | ||
|
||
* MinimumLogLevel: The minimum log level for messages to be sent to Raygun. Defaults to `LogLevel.Error`. | ||
* OnlyLogExceptions: If false, logs without exceptions will be sent to Raygun. Defaults to `true`. | ||
|
||
These can be set in code: | ||
|
||
```csharp | ||
builder.Logging.AddRaygunLogger(options: options => | ||
{ | ||
options.MinimumLogLevel = LogLevel.Information; | ||
options.OnlyLogExceptions = false; | ||
}); | ||
``` | ||
|
||
Or in the `appsettings.json` file: | ||
|
||
```json | ||
{ | ||
"RaygunSettings": { | ||
"MinimumLogLevel": "Information", | ||
"OnlyLogExceptions": false | ||
} | ||
} | ||
``` | ||
|
||
## Notes | ||
|
||
The category/contextSource set as a tag in Raygun. | ||
|
||
When logs are sent without an exception, a Custom Data property is added to the Raygun message with the | ||
key `NullException` with the value `Logged without exception` to identify Raygun Logs that have no exception. |
Oops, something went wrong.