Skip to content

Commit 483d025

Browse files
committed
update to MongoDB.Driver 3.1
1 parent eb5b9b4 commit 483d025

File tree

6 files changed

+651
-651
lines changed

6 files changed

+651
-651
lines changed

src/NLog.Mongo/ExceptionHelper.cs

Lines changed: 63 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,86 @@
1-
using System;
2-
using System.Threading;
31
using NLog.Common;
42

5-
namespace NLog.Mongo
3+
namespace NLog.Mongo;
4+
5+
internal static class ExceptionHelper
66
{
7-
internal static class ExceptionHelper
8-
{
9-
private const string LoggedKey = "NLog.ExceptionLoggedToInternalLogger";
7+
private const string LoggedKey = "NLog.ExceptionLoggedToInternalLogger";
108

11-
/// <summary>
12-
/// Mark this exception as logged to the <see cref="InternalLogger"/>.
13-
/// </summary>
14-
/// <param name="exception"></param>
15-
/// <returns></returns>
16-
public static void MarkAsLoggedToInternalLogger(this Exception exception)
9+
/// <summary>
10+
/// Mark this exception as logged to the <see cref="InternalLogger"/>.
11+
/// </summary>
12+
/// <param name="exception"></param>
13+
/// <returns></returns>
14+
public static void MarkAsLoggedToInternalLogger(this Exception exception)
15+
{
16+
if (exception != null)
1717
{
18-
if (exception != null)
19-
{
20-
exception.Data[LoggedKey] = true;
21-
}
18+
exception.Data[LoggedKey] = true;
2219
}
20+
}
2321

24-
/// <summary>
25-
/// Is this exception logged to the <see cref="InternalLogger"/>?
26-
/// </summary>
27-
/// <param name="exception"></param>
28-
/// <returns><c>true</c>if the <paramref name="exception"/> has been logged to the <see cref="InternalLogger"/>.</returns>
29-
public static bool IsLoggedToInternalLogger(this Exception exception)
22+
/// <summary>
23+
/// Is this exception logged to the <see cref="InternalLogger"/>?
24+
/// </summary>
25+
/// <param name="exception"></param>
26+
/// <returns><c>true</c>if the <paramref name="exception"/> has been logged to the <see cref="InternalLogger"/>.</returns>
27+
public static bool IsLoggedToInternalLogger(this Exception exception)
28+
{
29+
if (exception != null)
3030
{
31-
if (exception != null)
32-
{
33-
return exception.Data[LoggedKey] as bool? ?? false;
34-
}
35-
return false;
31+
return exception.Data[LoggedKey] as bool? ?? false;
3632
}
33+
return false;
34+
}
3735

3836

39-
/// <summary>
40-
/// Determines whether the exception must be rethrown and logs the error to the <see cref="InternalLogger"/> if <see cref="IsLoggedToInternalLogger"/> is <c>false</c>.
41-
///
42-
/// Advised to log first the error to the <see cref="InternalLogger"/> before calling this method.
43-
/// </summary>
44-
/// <param name="exception">The exception to check.</param>
45-
/// <returns><c>true</c>if the <paramref name="exception"/> must be rethrown, <c>false</c> otherwise.</returns>
46-
public static bool MustBeRethrown(this Exception exception)
47-
{
48-
if (exception.MustBeRethrownImmediately())
49-
return true;
50-
51-
var isConfigError = exception is NLogConfigurationException;
37+
/// <summary>
38+
/// Determines whether the exception must be rethrown and logs the error to the <see cref="InternalLogger"/> if <see cref="IsLoggedToInternalLogger"/> is <c>false</c>.
39+
///
40+
/// Advised to log first the error to the <see cref="InternalLogger"/> before calling this method.
41+
/// </summary>
42+
/// <param name="exception">The exception to check.</param>
43+
/// <returns><c>true</c>if the <paramref name="exception"/> must be rethrown, <c>false</c> otherwise.</returns>
44+
public static bool MustBeRethrown(this Exception exception)
45+
{
46+
if (exception.MustBeRethrownImmediately())
47+
return true;
5248

53-
//we throw always configuration exceptions (historical)
54-
if (!exception.IsLoggedToInternalLogger())
55-
{
56-
var level = isConfigError ? LogLevel.Warn : LogLevel.Error;
57-
InternalLogger.Log(exception, level, "Error has been raised.");
58-
}
49+
var isConfigError = exception is NLogConfigurationException;
5950

60-
//if ThrowConfigExceptions == null, use ThrowExceptions
61-
var shallRethrow = isConfigError ? (LogManager.ThrowConfigExceptions ?? LogManager.ThrowExceptions) : LogManager.ThrowExceptions;
62-
return shallRethrow;
51+
//we throw always configuration exceptions (historical)
52+
if (!exception.IsLoggedToInternalLogger())
53+
{
54+
var level = isConfigError ? LogLevel.Warn : LogLevel.Error;
55+
InternalLogger.Log(exception, level, "Error has been raised.");
6356
}
6457

65-
/// <summary>
66-
/// Determines whether the exception must be rethrown immediately, without logging the error to the <see cref="InternalLogger"/>.
67-
///
68-
/// Only used this method in special cases.
69-
/// </summary>
70-
/// <param name="exception">The exception to check.</param>
71-
/// <returns><c>true</c>if the <paramref name="exception"/> must be rethrown, <c>false</c> otherwise.</returns>
72-
public static bool MustBeRethrownImmediately(this Exception exception)
73-
{
58+
//if ThrowConfigExceptions == null, use ThrowExceptions
59+
var shallRethrow = isConfigError ? (LogManager.ThrowConfigExceptions ?? LogManager.ThrowExceptions) : LogManager.ThrowExceptions;
60+
return shallRethrow;
61+
}
62+
63+
/// <summary>
64+
/// Determines whether the exception must be rethrown immediately, without logging the error to the <see cref="InternalLogger"/>.
65+
///
66+
/// Only used this method in special cases.
67+
/// </summary>
68+
/// <param name="exception">The exception to check.</param>
69+
/// <returns><c>true</c>if the <paramref name="exception"/> must be rethrown, <c>false</c> otherwise.</returns>
70+
public static bool MustBeRethrownImmediately(this Exception exception)
71+
{
7472

7573
#if !NETSTANDARD1_5
76-
if (exception is StackOverflowException)
77-
return true;
74+
if (exception is StackOverflowException)
75+
return true;
7876

79-
if (exception is ThreadAbortException)
80-
return true;
77+
if (exception is ThreadAbortException)
78+
return true;
8179
#endif
8280

83-
if (exception is OutOfMemoryException)
84-
return true;
81+
if (exception is OutOfMemoryException)
82+
return true;
8583

86-
return false;
87-
}
84+
return false;
8885
}
8986
}

0 commit comments

Comments
 (0)