Skip to content

Commit 4bf9aa9

Browse files
committed
improve logging
1 parent 41c4917 commit 4bf9aa9

3 files changed

Lines changed: 69 additions & 84 deletions

File tree

NpgsqlRest/Defaults/DefaultCommentParser.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System.Xml.Linq;
2-
using Microsoft.Extensions.Primitives;
1+
using Microsoft.Extensions.Primitives;
32

43
namespace NpgsqlRest.Defaults;
54

@@ -207,7 +206,7 @@ internal static class DefaultCommentParser
207206
}
208207
else
209208
{
210-
logger?.InvalidHttpMethodComment(words[1], routine.Schema, routine.Name, routineEndpoint.Method.ToString());
209+
logger?.InvalidHttpMethodComment(words[1], routine.Schema, routine.Name, routineEndpoint.Method);
211210
}
212211
}
213212
if (len == 3)
@@ -230,7 +229,7 @@ internal static class DefaultCommentParser
230229
{
231230
if (options.LogAnnotationSetInfo)
232231
{
233-
logger?.CommentSetHttp(routine.Type.ToString(), routine.Schema, routine.Name, routineEndpoint.Method.ToString(), routineEndpoint.Url);
232+
logger?.CommentSetHttp(routine.Type, routine.Schema, routine.Name, routineEndpoint.Method, routineEndpoint.Url);
234233
}
235234
}
236235
}
@@ -253,14 +252,14 @@ internal static class DefaultCommentParser
253252
}
254253
else
255254
{
256-
logger?.InvalidParameterTypeComment(words[1], routine.Schema, routine.Name, routineEndpoint.RequestParamType.ToString());
255+
logger?.InvalidParameterTypeComment(words[1], routine.Schema, routine.Name, routineEndpoint.RequestParamType);
257256
}
258257

259258
if (originalParamType != routineEndpoint.RequestParamType)
260259
{
261260
if (options.LogAnnotationSetInfo)
262261
{
263-
logger?.CommentSetParameterType(routine.Type.ToString(), routine.Schema, routine.Name, routineEndpoint.RequestParamType.ToString());
262+
logger?.CommentSetParameterType(routine.Type, routine.Schema, routine.Name, routineEndpoint.RequestParamType);
264263
}
265264
}
266265
}
@@ -274,7 +273,7 @@ internal static class DefaultCommentParser
274273
routineEndpoint.RequiresAuthorization = true;
275274
if (options.LogAnnotationSetInfo)
276275
{
277-
logger?.CommentSetAuth(routine.Type.ToString(), routine.Schema, routine.Name);
276+
logger?.CommentSetAuth(routine.Type, routine.Schema, routine.Name);
278277
}
279278
}
280279

@@ -290,14 +289,14 @@ internal static class DefaultCommentParser
290289
{
291290
if (options.LogAnnotationSetInfo)
292291
{
293-
logger?.CommentSetTimeout(routine.Type.ToString(), routine.Schema, routine.Name, words[1]);
292+
logger?.CommentSetTimeout(routine.Type, routine.Schema, routine.Name, words[1]);
294293
}
295294
}
296295
routineEndpoint.CommandTimeout = parsedTimeout;
297296
}
298297
else
299298
{
300-
logger?.InvalidTimeoutComment(words[1], routine.Schema, routine.Name, routineEndpoint.CommandTimeout?.ToString() ?? "NULL");
299+
logger?.InvalidTimeoutComment(words[1], routine.Schema, routine.Name, routineEndpoint.CommandTimeout);
301300
}
302301
}
303302

@@ -323,13 +322,13 @@ internal static class DefaultCommentParser
323322
}
324323
else
325324
{
326-
logger?.InvalidRequestHeadersModeComment(words[1], routine.Schema, routine.Name, routineEndpoint.RequestHeadersMode.ToString());
325+
logger?.InvalidRequestHeadersModeComment(words[1], routine.Schema, routine.Name, routineEndpoint.RequestHeadersMode);
327326
}
328327
if (routineEndpoint.RequestHeadersMode != options.RequestHeadersMode)
329328
{
330329
if (options.LogAnnotationSetInfo)
331330
{
332-
logger?.CommentSetRequestHeadersMode(routine.Type.ToString(), routine.Schema, routine.Name, words[1]);
331+
logger?.CommentSetRequestHeadersMode(routine.Type, routine.Schema, routine.Name, words[1]);
333332
}
334333
}
335334
}
@@ -348,7 +347,7 @@ internal static class DefaultCommentParser
348347
{
349348
if (options.LogAnnotationSetInfo)
350349
{
351-
logger?.CommentSetRequestHeadersParamName(routine.Type.ToString(), routine.Schema, routine.Name, words[1]);
350+
logger?.CommentSetRequestHeadersParamName(routine.Type, routine.Schema, routine.Name, words[1]);
352351
}
353352
}
354353
routineEndpoint.RequestHeadersParameterName = words[1];
@@ -369,7 +368,7 @@ internal static class DefaultCommentParser
369368
{
370369
if (options.LogAnnotationSetInfo)
371370
{
372-
logger?.CommentSetBodyParamName(routine.Type.ToString(), routine.Schema, routine.Name, words[1]);
371+
logger?.CommentSetBodyParamName(routine.Type, routine.Schema, routine.Name, words[1]);
373372
}
374373
}
375374
routineEndpoint.BodyParameterName = words[1];
@@ -395,13 +394,13 @@ internal static class DefaultCommentParser
395394
}
396395
else
397396
{
398-
logger?.InvalidResponseNullHandlingModeComment(words[1], routine.Schema, routine.Name, routineEndpoint.TextResponseNullHandling.ToString());
397+
logger?.InvalidResponseNullHandlingModeComment(words[1], routine.Schema, routine.Name, routineEndpoint.TextResponseNullHandling);
399398
}
400399
if (routineEndpoint.TextResponseNullHandling != options.TextResponseNullHandling)
401400
{
402401
if (options.LogAnnotationSetInfo)
403402
{
404-
logger?.CommentSetTextResponseNullHandling(routine.Type.ToString(), routine.Schema, routine.Name, words[1]);
403+
logger?.CommentSetTextResponseNullHandling(routine.Type, routine.Schema, routine.Name, words[1]);
405404
}
406405
}
407406
}
@@ -425,13 +424,13 @@ internal static class DefaultCommentParser
425424
}
426425
else
427426
{
428-
logger?.InvalidQueryStringNullHandlingComment(words[1], routine.Schema, routine.Name, routineEndpoint.QueryStringNullHandling.ToString());
427+
logger?.InvalidQueryStringNullHandlingComment(words[1], routine.Schema, routine.Name, routineEndpoint.QueryStringNullHandling);
429428
}
430429
if (routineEndpoint.TextResponseNullHandling != options.TextResponseNullHandling)
431430
{
432431
if (options.LogAnnotationSetInfo)
433432
{
434-
logger?.CommentSetQueryStringNullHandling(routine.Type.ToString(), routine.Schema, routine.Name, routineEndpoint.QueryStringNullHandling.ToString());
433+
logger?.CommentSetQueryStringNullHandling(routine.Type, routine.Schema, routine.Name, routineEndpoint.QueryStringNullHandling);
435434
}
436435
}
437436
}
@@ -451,7 +450,7 @@ internal static class DefaultCommentParser
451450
{
452451
if (options.LogAnnotationSetInfo)
453452
{
454-
logger?.CommentSetContentType(routine.Type.ToString(), routine.Schema, routine.Name, headerValue);
453+
logger?.CommentSetContentType(routine.Type, routine.Schema, routine.Name, headerValue);
455454
}
456455
}
457456
routineEndpoint.ResponseContentType = headerValue;
@@ -480,7 +479,7 @@ internal static class DefaultCommentParser
480479
{
481480
if (options.LogAnnotationSetInfo)
482481
{
483-
logger?.CommentSetHeader(routine.Type.ToString(), routine.Schema, routine.Name, headerName, headerValue);
482+
logger?.CommentSetHeader(routine.Type, routine.Schema, routine.Name, headerName, headerValue);
484483
}
485484
}
486485
}

NpgsqlRest/Defaults/DefaultEndpoint.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@ internal static class DefaultEndpoint
5858
if (options.LogCommands && logger != null)
5959
{
6060
routineEndpoint.LogCallback = LoggerMessage.Define<string, string>(LogLevel.Information,
61-
new EventId(-1, nameof(routineEndpoint.LogCallback)),
61+
new EventId(0, nameof(routineEndpoint.LogCallback)),
6262
"{parameters}{command}",
63-
new LogDefineOptions() { SkipEnabledCheck = true });
63+
Logger.LogDefineOptions);
6464
}
6565
else
6666
{

0 commit comments

Comments
 (0)