Skip to content

Commit

Permalink
chore: review stuffs
Browse files Browse the repository at this point in the history
  • Loading branch information
NatMarchand committed Sep 7, 2023
1 parent c4ef714 commit 93b3f2d
Show file tree
Hide file tree
Showing 18 changed files with 95 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
PostgreSqlConnectionString: Server=localhost;Port=${{ job.services.postgres.ports[5432] }};Database=test;User Id=postgres;Password=postgres;
SQLServerConnectionString: Server=tcp:127.0.0.1,${{ job.services.sqlserver.ports[1433] }};Database=tempdb;User Id=sa;Password=g0d4mm!tSQLServer;
- name: .NET Lib Pack
run: dotnet pack Build.csproj --no-build -c Release /p:Packing=true /p:PackageOutputPath=%CD%\.nupkgs /p:CI=true
run: dotnet pack Build.csproj --no-build -c Release /p:Packing=true /p:PackageOutputPath=$PWD/.nupkgs /p:CI=true
24 changes: 12 additions & 12 deletions StackExchange.Exceptional.sln
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackExchange.Exceptional.M
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Samples.ConsoleNetCore", "samples\Samples.ConsoleNetCore\Samples.ConsoleNetCore.csproj", "{6CE269E1-6DC9-43A4-B6B8-683CE8A19E6A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackExchange.Exceptional.MicrosoftDataSqlClient", "src\StackExchange.Exceptional.MicrosoftDataSqlClient\StackExchange.Exceptional.MicrosoftDataSqlClient.csproj", "{B575D666-06E5-4C5C-84CF-C9749C6D3E6B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackExchange.Exceptional.MicrosoftDataSql", "src\StackExchange.Exceptional.MicrosoftDataSql\StackExchange.Exceptional.MicrosoftDataSql.csproj", "{4FFED4CE-F0B8-4E9E-B7F9-684CA52F5D4F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StackExchange.Exceptional.SystemDataSqlClient", "src\StackExchange.Exceptional.SystemDataSqlClient\StackExchange.Exceptional.SystemDataSqlClient.csproj", "{DF5184E1-D8FF-4C29-BF87-991596FE30A7}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StackExchange.Exceptional.SystemDataSql", "src\StackExchange.Exceptional.SystemDataSql\StackExchange.Exceptional.SystemDataSql.csproj", "{41C614C7-2932-4ECD-B592-373BAA515031}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -122,14 +122,14 @@ Global
{6CE269E1-6DC9-43A4-B6B8-683CE8A19E6A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6CE269E1-6DC9-43A4-B6B8-683CE8A19E6A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6CE269E1-6DC9-43A4-B6B8-683CE8A19E6A}.Release|Any CPU.Build.0 = Release|Any CPU
{B575D666-06E5-4C5C-84CF-C9749C6D3E6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B575D666-06E5-4C5C-84CF-C9749C6D3E6B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B575D666-06E5-4C5C-84CF-C9749C6D3E6B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B575D666-06E5-4C5C-84CF-C9749C6D3E6B}.Release|Any CPU.Build.0 = Release|Any CPU
{DF5184E1-D8FF-4C29-BF87-991596FE30A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF5184E1-D8FF-4C29-BF87-991596FE30A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF5184E1-D8FF-4C29-BF87-991596FE30A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF5184E1-D8FF-4C29-BF87-991596FE30A7}.Release|Any CPU.Build.0 = Release|Any CPU
{4FFED4CE-F0B8-4E9E-B7F9-684CA52F5D4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4FFED4CE-F0B8-4E9E-B7F9-684CA52F5D4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4FFED4CE-F0B8-4E9E-B7F9-684CA52F5D4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4FFED4CE-F0B8-4E9E-B7F9-684CA52F5D4F}.Release|Any CPU.Build.0 = Release|Any CPU
{41C614C7-2932-4ECD-B592-373BAA515031}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41C614C7-2932-4ECD-B592-373BAA515031}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41C614C7-2932-4ECD-B592-373BAA515031}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41C614C7-2932-4ECD-B592-373BAA515031}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -147,8 +147,8 @@ Global
{0A412433-C2CE-4EBE-BB5A-C3E48983E941} = {8B91532F-A112-4F73-80BD-A95B7359BBC3}
{8CFA59A5-5180-4466-A32E-507F3D541163} = {8B91532F-A112-4F73-80BD-A95B7359BBC3}
{6CE269E1-6DC9-43A4-B6B8-683CE8A19E6A} = {001E5AA4-42C8-4AC3-B14A-AF1DFA02E9FB}
{B575D666-06E5-4C5C-84CF-C9749C6D3E6B} = {8B91532F-A112-4F73-80BD-A95B7359BBC3}
{DF5184E1-D8FF-4C29-BF87-991596FE30A7} = {8B91532F-A112-4F73-80BD-A95B7359BBC3}
{4FFED4CE-F0B8-4E9E-B7F9-684CA52F5D4F} = {8B91532F-A112-4F73-80BD-A95B7359BBC3}
{41C614C7-2932-4ECD-B592-373BAA515031} = {8B91532F-A112-4F73-80BD-A95B7359BBC3}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7F066A86-14D8-4A2C-848A-D4371BB704FA}
Expand Down
2 changes: 1 addition & 1 deletion samples/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
<PackageVersion Include="Microsoft.AspNet.Web.Optimization" Version="1.1.3" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
<GlobalPackageReference Condition="'$(TargetFramework)'=='net6.0'" Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Dapper" Version="2.0.123" />
<PackageVersion Include="Dapper" Version="2.0.151" />
<PackageVersion Include="Microsoft.Data.SqlClient" Version="5.1.1" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="6.0.0" />
Expand All @@ -16,7 +16,7 @@
<PackageVersion Include="System.Data.SqlClient" Version="4.8.5" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
<GlobalPackageReference Condition="'$(TargetFramework)'!='net462'" Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" />
<GlobalPackageReference Include="Nerdbank.GitVersioning" Version="3.6.132" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace StackExchange.Exceptional.Stores
/// <summary>
/// An <see cref="ErrorStore"/> implementation that uses SQL Server as its backing store.
/// </summary>
public sealed class SQLErrorStore : ErrorStore
public sealed class MicrosoftDataSQLErrorStore : ErrorStore
{
/// <summary>
/// Name for this error store.
Expand All @@ -28,12 +28,12 @@ public sealed class SQLErrorStore : ErrorStore
public const int MaximumDisplayCount = 500;

/// <summary>
/// Creates a new instance of <see cref="SQLErrorStore"/> with the specified connection string.
/// Creates a new instance of <see cref="MicrosoftDataSQLErrorStore"/> with the specified connection string.
/// The default table name is "Exceptions".
/// </summary>
/// <param name="connectionString">The database connection string to use.</param>
/// <param name="applicationName">The application name to use when logging.</param>
public SQLErrorStore(string connectionString, string applicationName)
public MicrosoftDataSQLErrorStore(string connectionString, string applicationName)
: this(new ErrorStoreSettings()
{
ApplicationName = applicationName,
Expand All @@ -42,11 +42,11 @@ public SQLErrorStore(string connectionString, string applicationName)
{ }

/// <summary>
/// Creates a new instance of <see cref="SQLErrorStore"/> with the given configuration.
/// Creates a new instance of <see cref="MicrosoftDataSQLErrorStore"/> with the given configuration.
/// The default table name is "Exceptions".
/// </summary>
/// <param name="settings">The <see cref="ErrorStoreSettings"/> for this store.</param>
public SQLErrorStore(ErrorStoreSettings settings) : base(settings)
public MicrosoftDataSQLErrorStore(ErrorStoreSettings settings) : base(settings)
{
_displayCount = Math.Min(settings.Size, MaximumDisplayCount);
_connectionString = settings.ConnectionString;
Expand Down Expand Up @@ -346,9 +346,18 @@ protected override async Task<int> GetErrorCountAsync(DateTime? since = null, st

private SqlConnection GetConnection() => new(_connectionString);

static SQLErrorStore()
static MicrosoftDataSQLErrorStore()
{
Statics.Settings.ExceptionActions.AddSqlException();
Statics.DefaultExceptionActions
.AddHandler<SqlException>((e, se) =>
{
e.AddCommand(new Command("SQL Server Query", se.Data.Contains("SQL") ? se.Data["SQL"] as string : null)
.AddData(nameof(se.Server), se.Server)
.AddData(nameof(se.Number), se.Number.ToString())
.AddData(nameof(se.LineNumber), se.LineNumber.ToString())
.AddData(se.Procedure.HasValue(), nameof(se.Procedure), se.Procedure)
);
});
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>StackExchange.Exceptional.MicrosoftDataSqlClient</AssemblyName>
<AssemblyName>StackExchange.Exceptional.MicrosoftDataSql</AssemblyName>
<Description>Microsoft.Data.SqlClient storage provider for StackExchange.Exceptional</Description>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
<RootNamespace>StackExchange.Exceptional</RootNamespace>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void Register(IErrorNotifier notifier)
/// Data handlers, for adding any data desirable to an exception before logging, like Commands.
/// The key here is the full type name, e.g. "System.Data.SqlClient.SqlException"
/// </summary>
public Dictionary<string, Action<Error>> ExceptionActions { get; } = new Dictionary<string, Action<Error>>();
public Dictionary<string, Action<Error>> ExceptionActions { get; } = new(Statics.DefaultExceptionActions);

/// <summary>
/// The <see cref="Regex"/> of data keys to include. For example, "Redis.*" would include all keys that start with Redis.
Expand Down
29 changes: 27 additions & 2 deletions src/StackExchange.Exceptional.Shared/Internal/Statics.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
namespace StackExchange.Exceptional.Internal
using System;
using System.Collections.Generic;

namespace StackExchange.Exceptional.Internal
{
/// <summary>
/// Internal Exceptional static controls, not meant for consumption.
Expand All @@ -13,11 +16,33 @@ public static class Statics
/// In ASP.NET (non-Core) this is populated by the ConfigSettings load.
/// In ASP.NET Core this is populated by .Configure() in the DI pipeline.
/// </remarks>
public static ExceptionalSettingsBase Settings { get; set; } = new ExceptionalSettingsDefault();
public static ExceptionalSettingsBase Settings { get; set; }

/// <summary>
/// Returns whether an error passed in right now would be logged.
/// </summary>
public static bool IsLoggingEnabled { get; set; } = true;

/// <summary>
///
/// </summary>
public static Dictionary<string, Action<Error>> DefaultExceptionActions { get; }

static Statics()
{
DefaultExceptionActions = new Dictionary<string, Action<Error>>();
DefaultExceptionActions.AddHandler("StackRedis.CacheException",
(e, ex) =>
{
var cmd = e.AddCommand(new Command("Redis"));
foreach (string k in ex.Data.Keys)
{
var val = ex.Data[k] as string;
if (k == "redis-command") cmd.CommandString = val;
if (k.StartsWith("Redis-")) cmd.AddData(k.Substring("Redis-".Length), val);
}
});
Settings = new ExceptionalSettingsDefault();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<AssemblyName>StackExchange.Exceptional.SystemDataSqlClient</AssemblyName>
<AssemblyName>StackExchange.Exceptional.SystemDataSql</AssemblyName>
<Description>System.Data.SqlClient storage provider for StackExchange.Exceptional</Description>
<TargetFrameworks>net462;netstandard2.0</TargetFrameworks>
<RootNamespace>StackExchange.Exceptional</RootNamespace>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace StackExchange.Exceptional.Stores
/// <summary>
/// An <see cref="ErrorStore"/> implementation that uses SQL Server as its backing store.
/// </summary>
public sealed class SQLErrorStore : ErrorStore
public sealed class SystemDataSQLErrorStore : ErrorStore
{
/// <summary>
/// Name for this error store.
Expand All @@ -28,12 +28,12 @@ public sealed class SQLErrorStore : ErrorStore
public const int MaximumDisplayCount = 500;

/// <summary>
/// Creates a new instance of <see cref="SQLErrorStore"/> with the specified connection string.
/// Creates a new instance of <see cref="SystemDataSQLErrorStore"/> with the specified connection string.
/// The default table name is "Exceptions".
/// </summary>
/// <param name="connectionString">The database connection string to use.</param>
/// <param name="applicationName">The application name to use when logging.</param>
public SQLErrorStore(string connectionString, string applicationName)
public SystemDataSQLErrorStore(string connectionString, string applicationName)
: this(new ErrorStoreSettings()
{
ApplicationName = applicationName,
Expand All @@ -42,11 +42,11 @@ public SQLErrorStore(string connectionString, string applicationName)
{ }

/// <summary>
/// Creates a new instance of <see cref="SQLErrorStore"/> with the given configuration.
/// Creates a new instance of <see cref="SystemDataSQLErrorStore"/> with the given configuration.
/// The default table name is "Exceptions".
/// </summary>
/// <param name="settings">The <see cref="ErrorStoreSettings"/> for this store.</param>
public SQLErrorStore(ErrorStoreSettings settings) : base(settings)
public SystemDataSQLErrorStore(ErrorStoreSettings settings) : base(settings)
{
_displayCount = Math.Min(settings.Size, MaximumDisplayCount);
_connectionString = settings.ConnectionString;
Expand Down Expand Up @@ -346,9 +346,18 @@ protected override async Task<int> GetErrorCountAsync(DateTime? since = null, st

private SqlConnection GetConnection() => new(_connectionString);

static SQLErrorStore()
static SystemDataSQLErrorStore()
{
Statics.Settings.ExceptionActions.AddSqlException();
Statics.DefaultExceptionActions
.AddHandler<SqlException>((e, se) =>
{
e.AddCommand(new Command("SQL Server Query", se.Data.Contains("SQL") ? se.Data["SQL"] as string : null)
.AddData(nameof(se.Server), se.Server)
.AddData(nameof(se.Number), se.Number.ToString())
.AddData(nameof(se.LineNumber), se.LineNumber.ToString())
.AddData(se.Procedure.HasValue(), nameof(se.Procedure), se.Procedure)
);
});
}
}
}

This file was deleted.

2 changes: 1 addition & 1 deletion src/StackExchange.Exceptional/HandlerFactory.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Web;
using System.Web;

namespace StackExchange.Exceptional
{
Expand Down
10 changes: 5 additions & 5 deletions tests/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Jil" Version="2.17"/>
<PackageVersion Include="Jil" Version="2.17" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="6.0.10" />
<PackageVersion Include="xunit" Version="2.4.2"/>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageVersion Include="xunit" Version="2.5.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3"/>
<GlobalPackageReference Include="xunit.runner.visualstudio" Version="2.4.5"/>
<GlobalPackageReference Condition="'$(TargetFramework)'=='net6.0'" Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" />
<GlobalPackageReference Include="xunit.runner.visualstudio" Version="2.5.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ public void SQLStorage()
Assert.Equal("Server=.;Database=Local.Exceptions;Trusted_Connection=True;", settings.Store.ConnectionString);
Assert.Equal("MyExceptions", settings.Store.TableName);

Assert.IsType<SQLErrorStore>(settings.DefaultStore);
var sqlStore = settings.DefaultStore as SQLErrorStore;
Assert.IsType<MicrosoftDataSQLErrorStore>(settings.DefaultStore);
var sqlStore = settings.DefaultStore as MicrosoftDataSQLErrorStore;
Assert.Equal("Samples (ASP.NET Core SQL)", sqlStore.ApplicationName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void AppNameViaConfigure()
}

const string appName = "AppNameViaConfig";
Exceptional.Configure(settings => settings.DefaultStore = new SQLErrorStore(TestConfig.Current.SQLServerConnectionString, appName));
Exceptional.Configure(settings => settings.DefaultStore = new MicrosoftDataSQLErrorStore(TestConfig.Current.SQLServerConnectionString, appName));

Assert.Equal(appName, Exceptional.Settings.DefaultStore.ApplicationName);
Assert.Equal(appName, Statics.Settings.DefaultStore.ApplicationName);
Expand Down
Loading

0 comments on commit 93b3f2d

Please sign in to comment.