-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSdkLoggingConfiguration.cs
More file actions
65 lines (57 loc) · 2.5 KB
/
SdkLoggingConfiguration.cs
File metadata and controls
65 lines (57 loc) · 2.5 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
57
58
59
60
61
62
63
64
65
using System;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace APIMatic.Core.Utilities.Logger.Configuration
{
/// <summary>
/// Represents the configuration settings for SDK logging.
/// </summary>
public class SdkLoggingConfiguration
{
/// <summary>
/// Gets or sets the logger instance used for logging SDK messages.
/// </summary>
public ILogger Logger { get; }
/// <summary>
/// Gets or sets the log level for SDK logging.
/// </summary>
public LogLevel? LogLevel { get; }
/// <summary>
/// Gets or sets whether sensitive headers should be masked in logs.
/// </summary>
public bool MaskSensitiveHeaders { get; }
/// <summary>
/// Gets or sets the configuration for request logging.
/// </summary>
public RequestLoggingConfiguration RequestLoggingConfiguration { get; }
/// <summary>
/// Gets or sets the configuration for response logging.
/// </summary>
public ResponseLoggingConfiguration ResponseLoggingConfiguration { get; }
private SdkLoggingConfiguration(ILogger logger, LogLevel? logLevel, bool maskSensitiveHeaders,
RequestLoggingConfiguration requestLoggingConfiguration,
ResponseLoggingConfiguration responseLoggingConfiguration)
{
Logger = logger;
LogLevel = logLevel;
MaskSensitiveHeaders = maskSensitiveHeaders;
RequestLoggingConfiguration = requestLoggingConfiguration;
ResponseLoggingConfiguration = responseLoggingConfiguration;
}
public static SdkLoggingConfiguration Console() =>
new SdkLoggingConfiguration(ConsoleLogger.Instance, null, true,
RequestLoggingConfiguration.Default(),
ResponseLoggingConfiguration.Default());
public static SdkLoggingConfiguration Builder(ILogger logger, LogLevel? logLevel, bool maskSensitiveHeaders,
RequestLoggingConfiguration requestLoggingConfiguration,
ResponseLoggingConfiguration responseLoggingConfiguration)
{
return new SdkLoggingConfiguration(
logger ?? ConsoleLogger.Instance,
logLevel,
maskSensitiveHeaders,
requestLoggingConfiguration ?? RequestLoggingConfiguration.Default(),
responseLoggingConfiguration ?? ResponseLoggingConfiguration.Default());
}
}
}