forked from npgsql/npgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNpgsqlLoggingConfiguration.cs
More file actions
56 lines (49 loc) · 2.43 KB
/
NpgsqlLoggingConfiguration.cs
File metadata and controls
56 lines (49 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace Npgsql;
/// <summary>
/// Configures Npgsql logging
/// </summary>
public static class NpgsqlLoggingConfiguration
{
static NpgsqlLoggingConfiguration()
{
var nullFactory = new NullLoggerFactory();
ConnectionLogger = nullFactory.CreateLogger("Npgsql.Connection");
CommandLogger = nullFactory.CreateLogger("Npgsql.Command");
TransactionLogger = nullFactory.CreateLogger("Npgsql.Transaction");
CopyLogger = nullFactory.CreateLogger("Npgsql.Copy");
ReplicationLogger = nullFactory.CreateLogger("Npgsql.Replication");
ExceptionLogger = nullFactory.CreateLogger("Npgsql.Exception");
}
/// <summary>
/// Initializes Npgsql logging to use the provided <paramref name="loggerFactory" />.
/// Must be called before any Npgsql APIs are used.
/// </summary>
/// <param name="loggerFactory"></param>
/// <param name="parameterLoggingEnabled">
/// Determines whether parameter contents will be logged alongside SQL statements - this may reveal sensitive information.
/// Defaults to <see langword="false" />.
/// </param>
public static void InitializeLogging(ILoggerFactory loggerFactory, bool parameterLoggingEnabled = false)
{
ConnectionLogger = loggerFactory.CreateLogger("Npgsql.Connection");
CommandLogger = loggerFactory.CreateLogger("Npgsql.Command");
TransactionLogger = loggerFactory.CreateLogger("Npgsql.Transaction");
CopyLogger = loggerFactory.CreateLogger("Npgsql.Copy");
ReplicationLogger = loggerFactory.CreateLogger("Npgsql.Replication");
ExceptionLogger = loggerFactory.CreateLogger("Npgsql.Exception");
IsParameterLoggingEnabled = parameterLoggingEnabled;
}
internal static ILogger ConnectionLogger { get; private set; }
internal static ILogger CommandLogger { get; private set; }
internal static ILogger TransactionLogger { get; private set; }
internal static ILogger CopyLogger { get; private set; }
internal static ILogger ReplicationLogger { get; private set; }
internal static ILogger ExceptionLogger { get; private set; }
/// <summary>
/// Determines whether parameter contents will be logged alongside SQL statements - this may reveal sensitive information.
/// Defaults to false.
/// </summary>
internal static bool IsParameterLoggingEnabled { get; set; }
}