@@ -119,6 +119,18 @@ public static partial class Log
119
119
120
120
[ LoggerMessage ( Level = LogLevel . Information , Message = "{type} {schema}.{name} has set CACHED with parameters {cachedParams} by the comment annotation." ) ]
121
121
public static partial void CommentCached ( this ILogger logger , RoutineType type , string schema , string name , IEnumerable < string > cachedParams ) ;
122
+
123
+ [ LoggerMessage ( Level = LogLevel . Information , Message = "{type} {schema}.{name} has set PARSE RESPONSE to true by the comment annotation." ) ]
124
+ public static partial void CommentParseResponse ( this ILogger logger , RoutineType type , string schema , string name ) ;
125
+
126
+ [ LoggerMessage ( Level = LogLevel . Warning , Message = "{type} {schema}.{name} has set PARSE RESPONSE to true by the comment annotation but routine doesn't return a single value. Routine will NOT be parsed. Only single values can be parsed." ) ]
127
+ public static partial void CommentInvalidParseResponse ( this ILogger logger , RoutineType type , string schema , string name ) ;
128
+
129
+ [ LoggerMessage ( Level = LogLevel . Information , Message = "{type} {schema}.{name} has set CACHE EXPIRES IN to {value} by the comment annotation." ) ]
130
+ public static partial void CommentCacheExpiresIn ( this ILogger logger , RoutineType type , string schema , string name , TimeSpan value ) ;
131
+
132
+ [ LoggerMessage ( Level = LogLevel . Warning , Message = "{type} {schema}.{name} can't set CACHE EXPIRES IN value by the comment annotation. Invalid interval value: {value}" ) ]
133
+ public static partial void InvalidCacheExpiresIn ( this ILogger logger , RoutineType type , string schema , string name , string value ) ;
122
134
}
123
135
124
136
public static class NpgsqlRestLogger
@@ -130,7 +142,7 @@ public static class NpgsqlRestLogger
130
142
private const string Debug = "DEBUG" ;
131
143
private const string Error = "ERROR" ;
132
144
private const string Panic = "PANIC" ;
133
- private const string LogPattern = "{where} {message}" ;
145
+ private const string LogPattern = "{where}: \n {message}" ;
134
146
135
147
internal static readonly LogDefineOptions LogDefineOptions = new ( ) { SkipEnabledCheck = true } ;
136
148
@@ -197,36 +209,89 @@ public static void LogEndpoint(ILogger? logger, RoutineEndpoint endpoint, string
197
209
}
198
210
}
199
211
200
- public static void LogConnectionNotice ( ILogger ? logger , NpgsqlNoticeEventArgs args )
212
+ public static void LogConnectionNotice ( ILogger ? logger , NpgsqlNoticeEventArgs args , PostgresConnectionNoticeLoggingMode mode )
201
213
{
202
214
if ( logger is null )
203
215
{
204
216
return ;
205
217
}
206
- var severity = args . Notice . Severity ;
207
- var where = string . Concat ( args . Notice . Where , " " , severity ) ;
208
- if ( string . Equals ( Info , severity , StringComparison . OrdinalIgnoreCase ) ||
209
- string . Equals ( Log , severity , StringComparison . OrdinalIgnoreCase ) ||
210
- string . Equals ( Notice , severity , StringComparison . OrdinalIgnoreCase ) )
218
+ if ( string . Equals ( Info , args . Notice . Severity , StringComparison . OrdinalIgnoreCase ) ||
219
+ string . Equals ( Log , args . Notice . Severity , StringComparison . OrdinalIgnoreCase ) ||
220
+ string . Equals ( Notice , args . Notice . Severity , StringComparison . OrdinalIgnoreCase ) )
211
221
{
212
- LogInformation ( logger , where , args . Notice . MessageText ) ;
222
+ if ( mode == PostgresConnectionNoticeLoggingMode . MessageOnly )
223
+ {
224
+ logger . LogInformation ( args . Notice . MessageText ) ;
225
+ }
226
+ else if ( mode == PostgresConnectionNoticeLoggingMode . FirstStackFrameAndMessage )
227
+ {
228
+ LogInformation ( logger , args . Notice ? . Where ? . Split ( '\n ' ) . LastOrDefault ( ) ?? "" , args . Notice ? . MessageText ! ) ;
229
+ }
230
+ else if ( mode == PostgresConnectionNoticeLoggingMode . FullStackAndMessage )
231
+ {
232
+ LogInformation ( logger , args . Notice ? . Where , args . Notice ? . MessageText ! ) ;
233
+ }
213
234
}
214
- else if ( string . Equals ( Warning , severity , StringComparison . OrdinalIgnoreCase ) )
235
+ else if ( string . Equals ( Warning , args . Notice . Severity , StringComparison . OrdinalIgnoreCase ) )
215
236
{
216
- LogWarning ( logger , where , args . Notice . MessageText ) ;
237
+ if ( mode == PostgresConnectionNoticeLoggingMode . MessageOnly )
238
+ {
239
+ logger . LogWarning ( args . Notice . MessageText ) ;
240
+ }
241
+ else if ( mode == PostgresConnectionNoticeLoggingMode . FirstStackFrameAndMessage )
242
+ {
243
+ LogWarning ( logger , args . Notice ? . Where ? . Split ( '\n ' ) . Last ( ) ?? "" , args . Notice ? . MessageText ! ) ;
244
+ }
245
+ else if ( mode == PostgresConnectionNoticeLoggingMode . FullStackAndMessage )
246
+ {
247
+ LogWarning ( logger , args . Notice ? . Where , args . Notice ? . MessageText ! ) ;
248
+ }
217
249
}
218
- else if ( string . Equals ( Debug , severity , StringComparison . OrdinalIgnoreCase ) )
250
+ else if ( string . Equals ( Debug , args . Notice . Severity , StringComparison . OrdinalIgnoreCase ) )
219
251
{
220
- LogDebug ( logger , where , args . Notice . MessageText ) ;
252
+ if ( mode == PostgresConnectionNoticeLoggingMode . MessageOnly )
253
+ {
254
+ logger . LogDebug ( args . Notice . MessageText ) ;
255
+ }
256
+ else if ( mode == PostgresConnectionNoticeLoggingMode . FirstStackFrameAndMessage )
257
+ {
258
+ LogDebug ( logger , args . Notice ? . Where ? . Split ( '\n ' ) . Last ( ) ?? "" , args . Notice ? . MessageText ! ) ;
259
+ }
260
+ else if ( mode == PostgresConnectionNoticeLoggingMode . FullStackAndMessage )
261
+ {
262
+ LogDebug ( logger , args . Notice ? . Where , args . Notice ? . MessageText ! ) ;
263
+ }
221
264
}
222
- else if ( string . Equals ( Error , severity , StringComparison . OrdinalIgnoreCase ) ||
223
- string . Equals ( Panic , severity , StringComparison . OrdinalIgnoreCase ) )
265
+ else if ( string . Equals ( Error , args . Notice . Severity , StringComparison . OrdinalIgnoreCase ) ||
266
+ string . Equals ( Panic , args . Notice . Severity , StringComparison . OrdinalIgnoreCase ) )
224
267
{
225
- LogError ( logger , where , args . Notice . MessageText ) ;
268
+ if ( mode == PostgresConnectionNoticeLoggingMode . MessageOnly )
269
+ {
270
+ logger . LogError ( args . Notice . MessageText ) ;
271
+ }
272
+ else if ( mode == PostgresConnectionNoticeLoggingMode . FirstStackFrameAndMessage )
273
+ {
274
+ LogError ( logger , args . Notice ? . Where ? . Split ( '\n ' ) . Last ( ) ?? "" , args . Notice ? . MessageText ! ) ;
275
+ }
276
+ else if ( mode == PostgresConnectionNoticeLoggingMode . FullStackAndMessage )
277
+ {
278
+ LogError ( logger , args . Notice ? . Where , args . Notice ? . MessageText ! ) ;
279
+ }
226
280
}
227
281
else
228
282
{
229
- LogTrace ( logger , where , args . Notice . MessageText ) ;
283
+ if ( mode == PostgresConnectionNoticeLoggingMode . MessageOnly )
284
+ {
285
+ logger . LogTrace ( args . Notice . MessageText ) ;
286
+ }
287
+ else if ( mode == PostgresConnectionNoticeLoggingMode . FirstStackFrameAndMessage )
288
+ {
289
+ LogTrace ( logger , args . Notice ? . Where ? . Split ( '\n ' ) . Last ( ) ?? "" , args . Notice ? . MessageText ! ) ;
290
+ }
291
+ else if ( mode == PostgresConnectionNoticeLoggingMode . FullStackAndMessage )
292
+ {
293
+ LogTrace ( logger , args . Notice ? . Where , args . Notice ? . MessageText ! ) ;
294
+ }
230
295
}
231
296
}
232
297
}
0 commit comments