|
1 | 1 | /*
|
2 | 2 | * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
3 |
| - * |
| 3 | + * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License").
|
5 | 5 | * You may not use this file except in compliance with the License.
|
6 | 6 | * A copy of the License is located at
|
7 |
| - * |
| 7 | + * |
8 | 8 | * http://aws.amazon.com/apache2.0
|
9 |
| - * |
| 9 | + * |
10 | 10 | * or in the "license" file accompanying this file. This file is distributed
|
11 | 11 | * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
12 | 12 | * express or implied. See the License for the specific language governing
|
@@ -187,7 +187,7 @@ public static void Log(this ILogger logger, LogLevel logLevel, Exception excepti
|
187 | 187 | #region ExtraKeys Logger Extentions
|
188 | 188 |
|
189 | 189 | #region Debug
|
190 |
| - |
| 190 | + |
191 | 191 | /// <summary>
|
192 | 192 | /// Formats and writes a debug log message.
|
193 | 193 | /// </summary>
|
@@ -242,15 +242,16 @@ public static void LogDebug<T>(this ILogger logger, T extraKeys, Exception excep
|
242 | 242 | /// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
|
243 | 243 | /// <param name="args">An object array that contains zero or more objects to format.</param>
|
244 | 244 | /// <example>logger.LogDebug(extraKeys, "Processing request from {Address}", address)</example>
|
245 |
| - public static void LogDebug<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class |
| 245 | + public static void LogDebug<T>(this ILogger logger, T extraKeys, string message, params object[] args) |
| 246 | + where T : class |
246 | 247 | {
|
247 | 248 | Log(logger, LogLevel.Debug, extraKeys, message, args);
|
248 | 249 | }
|
249 |
| - |
| 250 | + |
250 | 251 | #endregion
|
251 | 252 |
|
252 | 253 | #region Trace
|
253 |
| - |
| 254 | + |
254 | 255 | /// <summary>
|
255 | 256 | /// Formats and writes a trace log message.
|
256 | 257 | /// </summary>
|
@@ -305,15 +306,16 @@ public static void LogTrace<T>(this ILogger logger, T extraKeys, Exception excep
|
305 | 306 | /// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
|
306 | 307 | /// <param name="args">An object array that contains zero or more objects to format.</param>
|
307 | 308 | /// <example>logger.LogTrace(extraKeys, "Processing request from {Address}", address)</example>
|
308 |
| - public static void LogTrace<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class |
| 309 | + public static void LogTrace<T>(this ILogger logger, T extraKeys, string message, params object[] args) |
| 310 | + where T : class |
309 | 311 | {
|
310 | 312 | Log(logger, LogLevel.Trace, extraKeys, message, args);
|
311 | 313 | }
|
312 | 314 |
|
313 | 315 | #endregion
|
314 | 316 |
|
315 | 317 | #region Information
|
316 |
| - |
| 318 | + |
317 | 319 | /// <summary>
|
318 | 320 | /// Formats and writes an informational log message.
|
319 | 321 | /// </summary>
|
@@ -368,11 +370,12 @@ public static void LogInformation<T>(this ILogger logger, T extraKeys, Exception
|
368 | 370 | /// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
|
369 | 371 | /// <param name="args">An object array that contains zero or more objects to format.</param>
|
370 | 372 | /// <example>logger.LogInformation(extraKeys, "Processing request from {Address}", address)</example>
|
371 |
| - public static void LogInformation<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class |
| 373 | + public static void LogInformation<T>(this ILogger logger, T extraKeys, string message, params object[] args) |
| 374 | + where T : class |
372 | 375 | {
|
373 | 376 | Log(logger, LogLevel.Information, extraKeys, message, args);
|
374 | 377 | }
|
375 |
| - |
| 378 | + |
376 | 379 | #endregion
|
377 | 380 |
|
378 | 381 | #region Warning
|
@@ -431,11 +434,12 @@ public static void LogWarning<T>(this ILogger logger, T extraKeys, Exception exc
|
431 | 434 | /// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
|
432 | 435 | /// <param name="args">An object array that contains zero or more objects to format.</param>
|
433 | 436 | /// <example>logger.LogWarning(extraKeys, "Processing request from {Address}", address)</example>
|
434 |
| - public static void LogWarning<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class |
| 437 | + public static void LogWarning<T>(this ILogger logger, T extraKeys, string message, params object[] args) |
| 438 | + where T : class |
435 | 439 | {
|
436 | 440 | Log(logger, LogLevel.Warning, extraKeys, message, args);
|
437 | 441 | }
|
438 |
| - |
| 442 | + |
439 | 443 | #endregion
|
440 | 444 |
|
441 | 445 | #region Error
|
@@ -494,7 +498,8 @@ public static void LogError<T>(this ILogger logger, T extraKeys, Exception excep
|
494 | 498 | /// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
|
495 | 499 | /// <param name="args">An object array that contains zero or more objects to format.</param>
|
496 | 500 | /// <example>logger.LogError(extraKeys, "Processing request from {Address}", address)</example>
|
497 |
| - public static void LogError<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class |
| 501 | + public static void LogError<T>(this ILogger logger, T extraKeys, string message, params object[] args) |
| 502 | + where T : class |
498 | 503 | {
|
499 | 504 | Log(logger, LogLevel.Error, extraKeys, message, args);
|
500 | 505 | }
|
@@ -557,15 +562,16 @@ public static void LogCritical<T>(this ILogger logger, T extraKeys, Exception ex
|
557 | 562 | /// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
|
558 | 563 | /// <param name="args">An object array that contains zero or more objects to format.</param>
|
559 | 564 | /// <example>logger.LogCritical(extraKeys, "Processing request from {Address}", address)</example>
|
560 |
| - public static void LogCritical<T>(this ILogger logger, T extraKeys, string message, params object[] args) where T : class |
| 565 | + public static void LogCritical<T>(this ILogger logger, T extraKeys, string message, params object[] args) |
| 566 | + where T : class |
561 | 567 | {
|
562 | 568 | Log(logger, LogLevel.Critical, extraKeys, message, args);
|
563 | 569 | }
|
564 | 570 |
|
565 | 571 | #endregion
|
566 | 572 |
|
567 | 573 | #region Log
|
568 |
| - |
| 574 | + |
569 | 575 | /// <summary>
|
570 | 576 | /// Formats and writes a log message at the specified log level.
|
571 | 577 | /// </summary>
|
@@ -630,11 +636,19 @@ public static void Log<T>(this ILogger logger, LogLevel logLevel, T extraKeys, E
|
630 | 636 | /// <param name="message">Format string of the log message in message template format. Example: <c>"User {User} logged in from {Address}"</c></param>
|
631 | 637 | /// <param name="args">An object array that contains zero or more objects to format.</param>
|
632 | 638 | /// <example>logger.Log(LogLevel.Information, extraKeys, "Processing request from {Address}", address)</example>
|
633 |
| - public static void Log<T>(this ILogger logger, LogLevel logLevel, T extraKeys, string message, params object[] args) where T : class |
| 639 | + public static void Log<T>(this ILogger logger, LogLevel logLevel, T extraKeys, string message, params object[] args) |
| 640 | + where T : class |
634 | 641 | {
|
635 |
| - Log(logger, logLevel, extraKeys, 0, null, message, args); |
| 642 | + try |
| 643 | + { |
| 644 | + Log(logger, logLevel, extraKeys, 0, null, message, args); |
| 645 | + } |
| 646 | + catch (Exception e) |
| 647 | + { |
| 648 | + logger.Log(LogLevel.Error, 0, e, "Powertools internal error"); |
| 649 | + } |
636 | 650 | }
|
637 |
| - |
| 651 | + |
638 | 652 | #endregion
|
639 | 653 |
|
640 | 654 | #endregion
|
|
0 commit comments