-
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.
bump to .NET 8.0 and stub out api and tests
- Loading branch information
1 parent
5a58f3e
commit f2902b6
Showing
47 changed files
with
1,196 additions
and
229 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
46 changes: 32 additions & 14 deletions
46
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 |
---|---|---|
@@ -1,20 +1,38 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<TargetFrameworks>netstandard2.0;netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.0" /> | ||
</ItemGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<AssemblyOriginatorKeyFile>..\Raygun.snk</AssemblyOriginatorKeyFile> | ||
<SignAssembly>true</SignAssembly> | ||
<IsPackable>true</IsPackable> | ||
<DebugType>embedded</DebugType> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Mindscape.Raygun4Net.NetCore\Mindscape.Raygun4Net.NetCore.csproj" /> | ||
</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.Abstractions" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" /> | ||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" 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,57 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Mindscape.Raygun4Net.Extensions.Logging; | ||
|
||
public class RaygunLogger : ILogger | ||
{ | ||
private readonly string _category; | ||
private readonly RaygunClientBase _client; | ||
private readonly RaygunLoggerSettings _settings; | ||
|
||
public RaygunLogger(string category, RaygunClientBase client, RaygunLoggerSettings settings) | ||
{ | ||
_category = category; | ||
_client = client; | ||
_settings = settings; | ||
} | ||
|
||
public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception? exception, Func<TState, Exception?, string> formatter) | ||
{ | ||
if (exception == null || !IsEnabled(logLevel)) | ||
{ | ||
return; | ||
} | ||
|
||
if (logLevel <= LogLevel.Error) | ||
{ | ||
_ = _client.SendInBackground(exception, new List<string> | ||
{ | ||
_category | ||
}, new Dictionary<string, string> | ||
{ | ||
["Message"] = formatter.Invoke(state, exception) | ||
}); | ||
} else if (logLevel == LogLevel.Critical) | ||
{ | ||
_client.SendInBackground(exception, new List<string> | ||
{ | ||
_category | ||
}, new Dictionary<string, string> | ||
{ | ||
["Message"] = formatter.Invoke(state, exception) | ||
// Force blocking call for critical exceptions to ensure they are logged as the application has potentially crashed. | ||
}).ConfigureAwait(false).GetAwaiter().GetResult(); | ||
} | ||
} | ||
|
||
public bool IsEnabled(LogLevel logLevel) | ||
{ | ||
return logLevel >= _settings.LogLevel; | ||
} | ||
|
||
public IDisposable BeginScope<TState>(TState state) | ||
{ | ||
// huh... | ||
return null; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
Mindscape.Raygun4Net.Extensions.Logging/RaygunLoggerExtensions.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,33 @@ | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Mindscape.Raygun4Net.Extensions.Logging; | ||
|
||
public static class RaygunLoggerExtensions | ||
{ | ||
public static ILoggingBuilder AddRaygunLogger(this ILoggingBuilder builder, IConfiguration? configuration = null, Action<RaygunLoggerSettings>? options = null) | ||
{ | ||
// Since we are not using IConfiguration, we need to create a new instance of RaygunSettings | ||
var settings = new RaygunLoggerSettings(); | ||
|
||
// Fetch settings from configuration or use default settings | ||
configuration?.GetSection("RaygunSettings").Bind(settings); | ||
|
||
// Override settings with user-provided settings | ||
options?.Invoke(settings); | ||
|
||
builder.Services.TryAddSingleton(settings); | ||
|
||
//builder.Services.TryAddSingleton<RaygunClientBase>(s => new RaygunClientBase(s.GetService<RaygunSettingsBase>()!, s.GetService<IRaygunUserProvider>()!)); | ||
builder.Services.AddSingleton<ILoggerProvider, RaygunLoggerProvider>(); | ||
|
||
return builder; | ||
} | ||
} | ||
|
||
public class RaygunLoggerSettings | ||
{ | ||
public LogLevel LogLevel { get; set; } = LogLevel.Error; | ||
} |
25 changes: 25 additions & 0 deletions
25
Mindscape.Raygun4Net.Extensions.Logging/RaygunLoggerProvider.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,25 @@ | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Mindscape.Raygun4Net.Extensions.Logging; | ||
|
||
public class RaygunLoggerProvider : ILoggerProvider | ||
{ | ||
//private readonly RaygunLoggerOptions _config; | ||
private readonly RaygunClientBase _client; | ||
private readonly RaygunLoggerSettings _settings; | ||
|
||
public RaygunLoggerProvider(RaygunClientBase client, RaygunLoggerSettings settings) | ||
{ | ||
_client = client; | ||
_settings = settings; | ||
} | ||
|
||
public ILogger CreateLogger(string categoryName) | ||
{ | ||
return new RaygunLogger(categoryName, _client, _settings); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
Mindscape.Raygun4Net.NetCore.Common/Mindscape.Raygun4Net.NetCore.Common.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
66 changes: 66 additions & 0 deletions
66
Mindscape.Raygun4Net.NetCore/ApplicationBuilderExtensions.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,66 @@ | ||
#nullable enable | ||
|
||
using System; | ||
using System.Linq; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.DependencyInjection.Extensions; | ||
|
||
namespace Mindscape.Raygun4Net.NetCore; | ||
|
||
public static class ApplicationBuilderExtensions | ||
{ | ||
/// <summary> | ||
/// Registers the Raygun Client and Raygun Settings with the DI container. Settings will be fetched from the appsettings.json file, | ||
/// and can be overridden by providing a custom configuration delegate. | ||
/// </summary> | ||
public static IServiceCollection AddRaygun(this IServiceCollection services, IConfiguration configuration, Action<RaygunSettings>? options = null) | ||
{ | ||
// Fetch settings from configuration or use default settings | ||
var settings = configuration.GetSection("RaygunSettings").Get<RaygunSettings>() ?? new RaygunSettings(); | ||
|
||
// Override settings with user-provided settings | ||
options?.Invoke(settings); | ||
|
||
services.TryAddSingleton(settings); | ||
services.TryAddSingleton<RaygunClientBase>(s => new RaygunClient(s.GetService<RaygunSettings>()!, s.GetService<IRaygunUserProvider>()!)); | ||
|
||
return services; | ||
} | ||
|
||
/// <summary> | ||
/// Registers the Raygun Client and Raygun Settings with the DI container. Settings will be defaulted and overridden by providing a custom configuration delegate. | ||
/// </summary> | ||
public static IServiceCollection AddRaygun(this IServiceCollection services, Action<RaygunSettings>? options) | ||
{ | ||
// Since we are not using IConfiguration, we need to create a new instance of RaygunSettings | ||
var settings = new RaygunSettings(); | ||
|
||
// Override settings with user-provided settings | ||
options?.Invoke(settings); | ||
|
||
services.TryAddSingleton(settings); | ||
services.TryAddSingleton<RaygunClientBase>(s => new RaygunClient(s.GetService<RaygunSettings>()!, s.GetService<IRaygunUserProvider>()!)); | ||
|
||
return services; | ||
} | ||
|
||
/// <summary> | ||
/// Registers a custom User Provider with the DI container. This allows you to provide your own implementation of IRaygunUserProvider. | ||
/// </summary> | ||
public static IServiceCollection AddRaygunUserProvider<T>(this IServiceCollection services) where T : class, IRaygunUserProvider | ||
{ | ||
// In case the default or any other user provider is already registered, remove it first | ||
var existing = services.FirstOrDefault(x => x.ServiceType == typeof(IRaygunUserProvider)); | ||
|
||
if (existing != null) | ||
{ | ||
services.Remove(existing); | ||
} | ||
|
||
// Add the new user provider | ||
services.TryAddSingleton<IRaygunUserProvider, T>(); | ||
|
||
return services; | ||
} | ||
} |
Oops, something went wrong.