-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Mohsen Esmailpour
committed
Sep 22, 2024
1 parent
9127ebf
commit 3120c2b
Showing
17 changed files
with
520 additions
and
392 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
104 changes: 52 additions & 52 deletions
104
src/Serilog.Ui.MsSqlServerProvider/Extensions/SerilogUiOptionBuilderExtensions.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 |
---|---|---|
@@ -1,64 +1,64 @@ | ||
using System; | ||
using Dapper; | ||
using Dapper; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Serilog.Ui.Core; | ||
using Serilog.Ui.Core.Interfaces; | ||
using Serilog.Ui.Core.Models.Options; | ||
using System; | ||
|
||
namespace Serilog.Ui.MsSqlServerProvider.Extensions | ||
{ | ||
/// <summary> | ||
/// SQL Server data provider specific extension methods for <see cref="ISerilogUiOptionsBuilder"/>. | ||
/// </summary> | ||
public static class SerilogUiOptionBuilderExtensions | ||
{ | ||
/// <summary>Configures the SerilogUi to connect to a SQL Server database.</summary> | ||
/// <param name="optionsBuilder"> The options builder. </param> | ||
/// <param name="setupOptions">The Ms Sql options action.</param> | ||
/// <param name="dateTimeCustomParsing"> | ||
/// Delegate to customize the DateTime parsing. | ||
/// It throws <see cref="InvalidOperationException" /> if the return DateTime isn't UTC kind. | ||
/// </param> | ||
public static ISerilogUiOptionsBuilder UseSqlServer( | ||
this ISerilogUiOptionsBuilder optionsBuilder, | ||
Action<RelationalDbOptions> setupOptions, | ||
Func<string, DateTime>? dateTimeCustomParsing = null | ||
) => optionsBuilder.UseSqlServer<SqlServerLogModel>(setupOptions, dateTimeCustomParsing); | ||
|
||
/// <summary>Configures the SerilogUi to connect to a SQL Server database.</summary> | ||
/// <typeparam name="T">The log model, containing any additional columns. It must inherit <see cref="SqlServerLogModel"/>.</typeparam> | ||
/// <param name="optionsBuilder"> The options builder. </param> | ||
/// <param name="setupOptions">The Ms Sql options action.</param> | ||
/// <param name="dateTimeCustomParsing"> | ||
/// Delegate to customize the DateTime parsing. | ||
/// It throws <see cref="InvalidOperationException" /> if the return DateTime isn't UTC kind. | ||
/// </param> | ||
public static ISerilogUiOptionsBuilder UseSqlServer<T>( | ||
this ISerilogUiOptionsBuilder optionsBuilder, | ||
Action<RelationalDbOptions> setupOptions, | ||
Func<string, DateTime>? dateTimeCustomParsing = null | ||
) where T : SqlServerLogModel | ||
{ | ||
var dbOptions = new RelationalDbOptions("dbo"); | ||
setupOptions(dbOptions); | ||
dbOptions.Validate(); | ||
|
||
var providerName = dbOptions.GetProviderName(SqlServerDataProvider.MsSqlProviderName); | ||
namespace Serilog.Ui.MsSqlServerProvider.Extensions; | ||
|
||
optionsBuilder.RegisterExceptionAsStringForProviderKey(providerName); | ||
SqlMapper.AddTypeHandler(new DapperDateTimeHandler(dateTimeCustomParsing)); | ||
/// <summary> | ||
/// SQL Server data provider specific extension methods for <see cref="ISerilogUiOptionsBuilder"/>. | ||
/// </summary> | ||
public static class SerilogUiOptionBuilderExtensions | ||
{ | ||
/// <summary>Configures the SerilogUi to connect to a SQL Server database.</summary> | ||
/// <param name="optionsBuilder"> The options builder. </param> | ||
/// <param name="setupOptions">The Ms Sql options action.</param> | ||
/// <param name="dateTimeCustomParsing"> | ||
/// Delegate to customize the DateTime parsing. | ||
/// It throws <see cref="InvalidOperationException" /> if the return DateTime isn't UTC kind. | ||
/// </param> | ||
public static ISerilogUiOptionsBuilder UseSqlServer( | ||
this ISerilogUiOptionsBuilder optionsBuilder, | ||
Action<RelationalDbOptions> setupOptions, | ||
Func<string, DateTime>? dateTimeCustomParsing = null | ||
) => optionsBuilder.UseSqlServer<SqlServerLogModel>(setupOptions, dateTimeCustomParsing); | ||
|
||
var customModel = typeof(T) != typeof(SqlServerLogModel); | ||
if (customModel) | ||
{ | ||
optionsBuilder.RegisterColumnsInfo<T>(providerName); | ||
optionsBuilder.Services.AddScoped<IDataProvider>(_ => new SqlServerDataProvider<T>(dbOptions)); | ||
/// <summary>Configures the SerilogUi to connect to a SQL Server database.</summary> | ||
/// <typeparam name="T">The log model, containing any additional columns. It must inherit <see cref="SqlServerLogModel"/>.</typeparam> | ||
/// <param name="optionsBuilder"> The options builder. </param> | ||
/// <param name="setupOptions">The Ms Sql options action.</param> | ||
/// <param name="dateTimeCustomParsing"> | ||
/// Delegate to customize the DateTime parsing. | ||
/// It throws <see cref="InvalidOperationException" /> if the return DateTime isn't UTC kind. | ||
/// </param> | ||
public static ISerilogUiOptionsBuilder UseSqlServer<T>( | ||
this ISerilogUiOptionsBuilder optionsBuilder, | ||
Action<RelationalDbOptions> setupOptions, | ||
Func<string, DateTime>? dateTimeCustomParsing = null | ||
) where T : SqlServerLogModel | ||
{ | ||
SqlServerDbOptions dbOptions = new("dbo"); | ||
setupOptions(dbOptions); | ||
dbOptions.Validate(); | ||
|
||
return optionsBuilder; | ||
} | ||
string providerName = dbOptions.GetProviderName(SqlServerDataProvider.MsSqlProviderName); | ||
optionsBuilder.RegisterExceptionAsStringForProviderKey(providerName); | ||
SqlMapper.AddTypeHandler(new DapperDateTimeHandler(dateTimeCustomParsing)); | ||
|
||
optionsBuilder.Services.AddScoped<IDataProvider>(_ => new SqlServerDataProvider(dbOptions)); | ||
return optionsBuilder; | ||
bool customModel = typeof(T) != typeof(SqlServerLogModel); | ||
if (customModel) | ||
{ | ||
optionsBuilder.RegisterColumnsInfo<T>(providerName); | ||
optionsBuilder.Services.AddScoped<IDataProvider>(_ => new SqlServerDataProvider<T>(dbOptions, new SqlServerQueryBuilder<T>())); | ||
} | ||
else | ||
{ | ||
optionsBuilder.Services.AddScoped<IDataProvider>(_ => | ||
new SqlServerDataProvider(dbOptions, new SqlServerQueryBuilder<SqlServerLogModel>())); | ||
} | ||
|
||
return optionsBuilder; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Serilog.Ui.MsSqlServerProvider/Extensions/SqlServerDbOptions.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,10 @@ | ||
using Serilog.Ui.Core.Models.Options; | ||
using Serilog.Ui.Core.QueryBuilder.Sql; | ||
using Serilog.Ui.MsSqlServerProvider.Models; | ||
|
||
namespace Serilog.Ui.MsSqlServerProvider.Extensions; | ||
|
||
public class SqlServerDbOptions(string defaultSchemaName) : RelationalDbOptions(defaultSchemaName) | ||
{ | ||
internal SinkColumnNames ColumnNames { get; } = new SqlServerSinkColumnNames(); | ||
} |
16 changes: 16 additions & 0 deletions
16
src/Serilog.Ui.MsSqlServerProvider/Models/SqlServerSinkColumnNames.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,16 @@ | ||
using Serilog.Ui.Core.QueryBuilder.Sql; | ||
|
||
namespace Serilog.Ui.MsSqlServerProvider.Models; | ||
|
||
internal class SqlServerSinkColumnNames : SinkColumnNames | ||
{ | ||
public SqlServerSinkColumnNames() | ||
{ | ||
Exception = "Exception"; | ||
Level = "Level"; | ||
LogEventSerialized = "Properties"; | ||
Message = "Message"; | ||
MessageTemplate = ""; | ||
Timestamp = "TimeStamp"; | ||
} | ||
} |
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
Oops, something went wrong.