1
- using System ;
2
- using Dapper ;
1
+ using Dapper ;
3
2
using Microsoft . Extensions . DependencyInjection ;
4
3
using Serilog . Ui . Core ;
5
4
using Serilog . Ui . Core . Interfaces ;
6
5
using Serilog . Ui . Core . Models . Options ;
6
+ using System ;
7
7
8
- namespace Serilog . Ui . MsSqlServerProvider . Extensions
9
- {
10
- /// <summary>
11
- /// SQL Server data provider specific extension methods for <see cref="ISerilogUiOptionsBuilder"/>.
12
- /// </summary>
13
- public static class SerilogUiOptionBuilderExtensions
14
- {
15
- /// <summary>Configures the SerilogUi to connect to a SQL Server database.</summary>
16
- /// <param name="optionsBuilder"> The options builder. </param>
17
- /// <param name="setupOptions">The Ms Sql options action.</param>
18
- /// <param name="dateTimeCustomParsing">
19
- /// Delegate to customize the DateTime parsing.
20
- /// It throws <see cref="InvalidOperationException" /> if the return DateTime isn't UTC kind.
21
- /// </param>
22
- public static ISerilogUiOptionsBuilder UseSqlServer (
23
- this ISerilogUiOptionsBuilder optionsBuilder ,
24
- Action < RelationalDbOptions > setupOptions ,
25
- Func < string , DateTime > ? dateTimeCustomParsing = null
26
- ) => optionsBuilder . UseSqlServer < SqlServerLogModel > ( setupOptions , dateTimeCustomParsing ) ;
27
-
28
- /// <summary>Configures the SerilogUi to connect to a SQL Server database.</summary>
29
- /// <typeparam name="T">The log model, containing any additional columns. It must inherit <see cref="SqlServerLogModel"/>.</typeparam>
30
- /// <param name="optionsBuilder"> The options builder. </param>
31
- /// <param name="setupOptions">The Ms Sql options action.</param>
32
- /// <param name="dateTimeCustomParsing">
33
- /// Delegate to customize the DateTime parsing.
34
- /// It throws <see cref="InvalidOperationException" /> if the return DateTime isn't UTC kind.
35
- /// </param>
36
- public static ISerilogUiOptionsBuilder UseSqlServer < T > (
37
- this ISerilogUiOptionsBuilder optionsBuilder ,
38
- Action < RelationalDbOptions > setupOptions ,
39
- Func < string , DateTime > ? dateTimeCustomParsing = null
40
- ) where T : SqlServerLogModel
41
- {
42
- var dbOptions = new RelationalDbOptions ( "dbo" ) ;
43
- setupOptions ( dbOptions ) ;
44
- dbOptions . Validate ( ) ;
45
-
46
- var providerName = dbOptions . GetProviderName ( SqlServerDataProvider . MsSqlProviderName ) ;
8
+ namespace Serilog . Ui . MsSqlServerProvider . Extensions ;
47
9
48
- optionsBuilder . RegisterExceptionAsStringForProviderKey ( providerName ) ;
49
- SqlMapper . AddTypeHandler ( new DapperDateTimeHandler ( dateTimeCustomParsing ) ) ;
10
+ /// <summary>
11
+ /// SQL Server data provider specific extension methods for <see cref="ISerilogUiOptionsBuilder"/>.
12
+ /// </summary>
13
+ public static class SerilogUiOptionBuilderExtensions
14
+ {
15
+ /// <summary>Configures the SerilogUi to connect to a SQL Server database.</summary>
16
+ /// <param name="optionsBuilder"> The options builder. </param>
17
+ /// <param name="setupOptions">The Ms Sql options action.</param>
18
+ /// <param name="dateTimeCustomParsing">
19
+ /// Delegate to customize the DateTime parsing.
20
+ /// It throws <see cref="InvalidOperationException" /> if the return DateTime isn't UTC kind.
21
+ /// </param>
22
+ public static ISerilogUiOptionsBuilder UseSqlServer (
23
+ this ISerilogUiOptionsBuilder optionsBuilder ,
24
+ Action < RelationalDbOptions > setupOptions ,
25
+ Func < string , DateTime > ? dateTimeCustomParsing = null
26
+ ) => optionsBuilder . UseSqlServer < SqlServerLogModel > ( setupOptions , dateTimeCustomParsing ) ;
50
27
51
- var customModel = typeof ( T ) != typeof ( SqlServerLogModel ) ;
52
- if ( customModel )
53
- {
54
- optionsBuilder . RegisterColumnsInfo < T > ( providerName ) ;
55
- optionsBuilder . Services . AddScoped < IDataProvider > ( _ => new SqlServerDataProvider < T > ( dbOptions ) ) ;
28
+ /// <summary>Configures the SerilogUi to connect to a SQL Server database.</summary>
29
+ /// <typeparam name="T">The log model, containing any additional columns. It must inherit <see cref="SqlServerLogModel"/>.</typeparam>
30
+ /// <param name="optionsBuilder"> The options builder. </param>
31
+ /// <param name="setupOptions">The Ms Sql options action.</param>
32
+ /// <param name="dateTimeCustomParsing">
33
+ /// Delegate to customize the DateTime parsing.
34
+ /// It throws <see cref="InvalidOperationException" /> if the return DateTime isn't UTC kind.
35
+ /// </param>
36
+ public static ISerilogUiOptionsBuilder UseSqlServer < T > (
37
+ this ISerilogUiOptionsBuilder optionsBuilder ,
38
+ Action < RelationalDbOptions > setupOptions ,
39
+ Func < string , DateTime > ? dateTimeCustomParsing = null
40
+ ) where T : SqlServerLogModel
41
+ {
42
+ SqlServerDbOptions dbOptions = new ( "dbo" ) ;
43
+ setupOptions ( dbOptions ) ;
44
+ dbOptions . Validate ( ) ;
56
45
57
- return optionsBuilder ;
58
- }
46
+ string providerName = dbOptions . GetProviderName ( SqlServerDataProvider . MsSqlProviderName ) ;
47
+ optionsBuilder . RegisterExceptionAsStringForProviderKey ( providerName ) ;
48
+ SqlMapper . AddTypeHandler ( new DapperDateTimeHandler ( dateTimeCustomParsing ) ) ;
59
49
60
- optionsBuilder . Services . AddScoped < IDataProvider > ( _ => new SqlServerDataProvider ( dbOptions ) ) ;
61
- return optionsBuilder ;
50
+ bool customModel = typeof ( T ) != typeof ( SqlServerLogModel ) ;
51
+ if ( customModel )
52
+ {
53
+ optionsBuilder . RegisterColumnsInfo < T > ( providerName ) ;
54
+ optionsBuilder . Services . AddScoped < IDataProvider > ( _ => new SqlServerDataProvider < T > ( dbOptions , new SqlServerQueryBuilder < T > ( ) ) ) ;
62
55
}
56
+ else
57
+ {
58
+ optionsBuilder . Services . AddScoped < IDataProvider > ( _ =>
59
+ new SqlServerDataProvider ( dbOptions , new SqlServerQueryBuilder < SqlServerLogModel > ( ) ) ) ;
60
+ }
61
+
62
+ return optionsBuilder ;
63
63
}
64
64
}
0 commit comments