Skip to content

Commit c1b0e1d

Browse files
committed
logging and documentation updates
1 parent 4a9f55e commit c1b0e1d

File tree

4 files changed

+222
-2
lines changed

4 files changed

+222
-2
lines changed

src/FluentCommand/ConcurrencyToken.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,37 @@
22

33
namespace FluentCommand;
44

5+
/// <summary>
6+
/// A structure to hold concurrency token
7+
/// </summary>
58
public readonly struct ConcurrencyToken : IEquatable<ConcurrencyToken>
69
{
10+
/// <summary>
11+
/// The default empty token
12+
/// </summary>
713
public static readonly ConcurrencyToken None = new(Array.Empty<byte>());
814

15+
/// <summary>
16+
/// Gets the underlying value of the token.
17+
/// </summary>
18+
/// <value>
19+
/// The underlying value of the token.
20+
/// </value>
921
public byte[] Value { get; }
1022

23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="ConcurrencyToken"/> struct.
25+
/// </summary>
26+
/// <param name="value">The value.</param>
1127
public ConcurrencyToken(byte[] value)
1228
{
1329
Value = value ?? Array.Empty<byte>();
1430
}
1531

32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="ConcurrencyToken"/> struct.
34+
/// </summary>
35+
/// <param name="value">The value.</param>
1636
public ConcurrencyToken(string value)
1737
{
1838
#if NET5_0_OR_GREATER
@@ -22,6 +42,7 @@ public ConcurrencyToken(string value)
2242
#endif
2343
}
2444

45+
/// <inheritdoc />
2546
public override string ToString()
2647
{
2748
#if NET5_0_OR_GREATER
@@ -31,16 +52,19 @@ public override string ToString()
3152
#endif
3253
}
3354

55+
/// <inheritdoc />
3456
public override bool Equals(object obj)
3557
{
3658
return obj is ConcurrencyToken token && Equals(token);
3759
}
3860

61+
/// <inheritdoc />
3962
public bool Equals(ConcurrencyToken other)
4063
{
4164
return EqualityComparer<byte[]>.Default.Equals(Value, other.Value);
4265
}
4366

67+
/// <inheritdoc />
4468
public override int GetHashCode()
4569
{
4670
return Value.GetHashCode();

src/FluentCommand/DataConfigurationBuilder.cs

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
namespace FluentCommand;
1111

12+
/// <summary>
13+
/// A configuration builder class
14+
/// </summary>
1215
public class DataConfigurationBuilder
1316
{
1417
private readonly IServiceCollection _services;
@@ -19,25 +22,52 @@ public class DataConfigurationBuilder
1922
private Type _queryGeneratorType;
2023
private Type _queryLoggerType;
2124

25+
/// <summary>
26+
/// Initializes a new instance of the <see cref="DataConfigurationBuilder"/> class.
27+
/// </summary>
28+
/// <param name="services">The services.</param>
2229
public DataConfigurationBuilder(IServiceCollection services)
2330
{
2431
_services = services;
2532
}
2633

2734

35+
/// <summary>
36+
/// The name of the connection to resolve the connection string from configuration.
37+
/// </summary>
38+
/// <param name="connectionName">Name of the connection.</param>
39+
/// <returns>
40+
/// The same configuration builder so that multiple calls can be chained.
41+
/// </returns>
2842
public DataConfigurationBuilder UseConnectionName(string connectionName)
2943
{
3044
_connectionName = connectionName;
3145
return this;
3246
}
3347

48+
/// <summary>
49+
/// The connection string to use with fluent command.
50+
/// </summary>
51+
/// <param name="connectionString">The connection string.</param>
52+
/// <returns>
53+
/// The same configuration builder so that multiple calls can be chained.
54+
/// </returns>
3455
public DataConfigurationBuilder UseConnectionString(string connectionString)
3556
{
3657
_connectionString = connectionString;
3758
return this;
3859
}
3960

4061

62+
/// <summary>
63+
/// Adds the provider factory to use with this configuration.
64+
/// </summary>
65+
/// <typeparam name="TService">The type of the service.</typeparam>
66+
/// <param name="providerFactory">The provider factory.</param>
67+
/// <returns>
68+
/// The same configuration builder so that multiple calls can be chained.
69+
/// </returns>
70+
/// <seealso cref="DbProviderFactory"/>
4171
public DataConfigurationBuilder AddProviderFactory<TService>(TService providerFactory)
4272
where TService : DbProviderFactory
4373
{
@@ -46,6 +76,15 @@ public DataConfigurationBuilder AddProviderFactory<TService>(TService providerFa
4676
return this;
4777
}
4878

79+
/// <summary>
80+
/// Adds the provider factory to use with this configuration.
81+
/// </summary>
82+
/// <typeparam name="TService">The type of the service.</typeparam>
83+
/// <param name="implementationFactory">The implementation factory.</param>
84+
/// <returns>
85+
/// The same configuration builder so that multiple calls can be chained.
86+
/// </returns>
87+
/// <seealso cref="DbProviderFactory"/>
4988
public DataConfigurationBuilder AddProviderFactory<TService>(Func<IServiceProvider, TService> implementationFactory)
5089
where TService : DbProviderFactory
5190
{
@@ -54,6 +93,14 @@ public DataConfigurationBuilder AddProviderFactory<TService>(Func<IServiceProvid
5493
return this;
5594
}
5695

96+
/// <summary>
97+
/// Adds the provider factory to use with this configuration.
98+
/// </summary>
99+
/// <typeparam name="TService">The type of the service.</typeparam>
100+
/// <returns>
101+
/// The same configuration builder so that multiple calls can be chained.
102+
/// </returns>
103+
/// <seealso cref="DbProviderFactory"/>
57104
public DataConfigurationBuilder AddProviderFactory<TService>()
58105
where TService : DbProviderFactory
59106
{
@@ -63,6 +110,15 @@ public DataConfigurationBuilder AddProviderFactory<TService>()
63110
}
64111

65112

113+
/// <summary>
114+
/// Adds the data cache service to use with this configuration.
115+
/// </summary>
116+
/// <typeparam name="TService">The type of the service.</typeparam>
117+
/// <param name="dataCache">The data cache.</param>
118+
/// <returns>
119+
/// The same configuration builder so that multiple calls can be chained.
120+
/// </returns>
121+
/// <seealso cref="IDataCache"/>
66122
public DataConfigurationBuilder AddDataCache<TService>(TService dataCache)
67123
where TService : class, IDataCache
68124
{
@@ -71,6 +127,15 @@ public DataConfigurationBuilder AddDataCache<TService>(TService dataCache)
71127
return this;
72128
}
73129

130+
/// <summary>
131+
/// Adds the data cache service to use with this configuration.
132+
/// </summary>
133+
/// <typeparam name="TService">The type of the service.</typeparam>
134+
/// <param name="implementationFactory">The implementation factory.</param>
135+
/// <returns>
136+
/// The same configuration builder so that multiple calls can be chained.
137+
/// </returns>
138+
/// <seealso cref="IDataCache"/>
74139
public DataConfigurationBuilder AddDataCache<TService>(Func<IServiceProvider, TService> implementationFactory)
75140
where TService : class, IDataCache
76141
{
@@ -79,6 +144,14 @@ public DataConfigurationBuilder AddDataCache<TService>(Func<IServiceProvider, TS
79144
return this;
80145
}
81146

147+
/// <summary>
148+
/// Adds the data cache service to use with this configuration.
149+
/// </summary>
150+
/// <typeparam name="TService">The type of the service.</typeparam>
151+
/// <returns>
152+
/// The same configuration builder so that multiple calls can be chained.
153+
/// </returns>
154+
/// <seealso cref="IDataCache"/>
82155
public DataConfigurationBuilder AddDataCache<TService>()
83156
where TService : class, IDataCache
84157
{
@@ -88,6 +161,15 @@ public DataConfigurationBuilder AddDataCache<TService>()
88161
}
89162

90163

164+
/// <summary>
165+
/// Adds the query generator service to use with this configuration.
166+
/// </summary>
167+
/// <typeparam name="TService">The type of the service.</typeparam>
168+
/// <param name="queryGenerator">The query generator.</param>
169+
/// <returns>
170+
/// The same configuration builder so that multiple calls can be chained.
171+
/// </returns>
172+
/// <seealso cref="IQueryGenerator"/>
91173
public DataConfigurationBuilder AddQueryGenerator<TService>(TService queryGenerator)
92174
where TService : class, IQueryGenerator
93175
{
@@ -96,6 +178,14 @@ public DataConfigurationBuilder AddQueryGenerator<TService>(TService queryGenera
96178
return this;
97179
}
98180

181+
/// <summary>
182+
/// Adds the query generator service to use with this configuration.
183+
/// </summary>
184+
/// <typeparam name="TService">The type of the service.</typeparam>
185+
/// <returns>
186+
/// The same configuration builder so that multiple calls can be chained.
187+
/// </returns>
188+
/// <seealso cref="IQueryGenerator"/>
99189
public DataConfigurationBuilder AddQueryGenerator<TService>()
100190
where TService : class, IQueryGenerator
101191
{
@@ -104,6 +194,15 @@ public DataConfigurationBuilder AddQueryGenerator<TService>()
104194
return this;
105195
}
106196

197+
/// <summary>
198+
/// Adds the query generator service to use with this configuration.
199+
/// </summary>
200+
/// <typeparam name="TService">The type of the service.</typeparam>
201+
/// <param name="implementationFactory">The implementation factory.</param>
202+
/// <returns>
203+
/// The same configuration builder so that multiple calls can be chained.
204+
/// </returns>
205+
/// <seealso cref="IQueryGenerator"/>
107206
public DataConfigurationBuilder AddQueryGenerator<TService>(Func<IServiceProvider, TService> implementationFactory)
108207
where TService : class, IQueryGenerator
109208
{
@@ -112,25 +211,52 @@ public DataConfigurationBuilder AddQueryGenerator<TService>(Func<IServiceProvide
112211
return this;
113212
}
114213

214+
/// <summary>
215+
/// Adds the SQL server generator to use with this configuration.
216+
/// </summary>
217+
/// <returns>
218+
/// The same configuration builder so that multiple calls can be chained.
219+
/// </returns>
115220
public DataConfigurationBuilder AddSqlServerGenerator()
116221
{
117222
AddQueryGenerator<SqlServerGenerator>();
118223
return this;
119224
}
120225

226+
/// <summary>
227+
/// Adds the sqlite generator to use with this configuration.
228+
/// </summary>
229+
/// <returns>
230+
/// The same configuration builder so that multiple calls can be chained.
231+
/// </returns>
121232
public DataConfigurationBuilder AddSqliteGenerator()
122233
{
123234
AddQueryGenerator<SqliteGenerator>();
124235
return this;
125236
}
126237

238+
/// <summary>
239+
/// Adds the PostgreSQL generator to use with this configuration.
240+
/// </summary>
241+
/// <returns>
242+
/// The same configuration builder so that multiple calls can be chained.
243+
/// </returns>
127244
public DataConfigurationBuilder AddPostgreSqlGenerator()
128245
{
129246
AddQueryGenerator<PostgreSqlGenerator>();
130247
return this;
131248
}
132249

133250

251+
/// <summary>
252+
/// Adds the query logger service to use with this configuration.
253+
/// </summary>
254+
/// <typeparam name="TService">The type of the service.</typeparam>
255+
/// <param name="queryLogger">The query logger.</param>
256+
/// <returns>
257+
/// The same configuration builder so that multiple calls can be chained.
258+
/// </returns>
259+
/// <seealso cref="IDataQueryLogger"/>
134260
public DataConfigurationBuilder AddQueryLogger<TService>(TService queryLogger)
135261
where TService : class, IDataQueryLogger
136262
{
@@ -139,6 +265,14 @@ public DataConfigurationBuilder AddQueryLogger<TService>(TService queryLogger)
139265
return this;
140266
}
141267

268+
/// <summary>
269+
/// Adds the query logger service to use with this configuration.
270+
/// </summary>
271+
/// <typeparam name="TService">The type of the service.</typeparam>
272+
/// <returns>
273+
/// The same configuration builder so that multiple calls can be chained.
274+
/// </returns>
275+
/// <seealso cref="IDataQueryLogger"/>
142276
public DataConfigurationBuilder AddQueryLogger<TService>()
143277
where TService : class, IDataQueryLogger
144278
{
@@ -147,6 +281,15 @@ public DataConfigurationBuilder AddQueryLogger<TService>()
147281
return this;
148282
}
149283

284+
/// <summary>
285+
/// Adds the query logger service to use with this configuration.
286+
/// </summary>
287+
/// <typeparam name="TService">The type of the service.</typeparam>
288+
/// <param name="implementationFactory">The implementation factory.</param>
289+
/// <returns>
290+
/// The same configuration builder so that multiple calls can be chained.
291+
/// </returns>
292+
/// <seealso cref="IDataQueryLogger"/>
150293
public DataConfigurationBuilder AddQueryLogger<TService>(Func<IServiceProvider, TService> implementationFactory)
151294
where TService : class, IDataQueryLogger
152295
{
@@ -156,6 +299,13 @@ public DataConfigurationBuilder AddQueryLogger<TService>(Func<IServiceProvider,
156299
}
157300

158301

302+
/// <summary>
303+
/// Adds services via the configuration setup action.
304+
/// </summary>
305+
/// <param name="setupAction">The configuration setup action.</param>
306+
/// <returns>
307+
/// The same configuration builder so that multiple calls can be chained.
308+
/// </returns>
159309
public DataConfigurationBuilder AddService(Action<IServiceCollection> setupAction)
160310
{
161311
setupAction(_services);

src/FluentCommand/DataQueryLogger.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace FluentCommand;
1010
/// A class to log queries to string delegate
1111
/// </summary>
1212
/// <seealso cref="FluentCommand.IDataQueryLogger" />
13-
public class DataQueryLogger : IDataQueryLogger
13+
public partial class DataQueryLogger : IDataQueryLogger
1414
{
1515
private readonly ILogger<DataQueryLogger> _logger;
1616
private readonly IDataQueryFormatter _formatter;
@@ -44,6 +44,15 @@ public virtual void LogCommand(IDbCommand command, TimeSpan duration, Exception
4444

4545
var output = _formatter.FormatCommand(command, duration, exception);
4646

47-
_logger.LogInformation(exception, output);
47+
if (exception == null)
48+
LogCommand(output);
49+
else
50+
LogError(output, exception);
4851
}
52+
53+
[LoggerMessage(0, LogLevel.Debug, "{output}")]
54+
public partial void LogCommand(string output);
55+
56+
[LoggerMessage(1, LogLevel.Error, "{output}")]
57+
public partial void LogError(string output, Exception exception);
4958
}

0 commit comments

Comments
 (0)