-
Notifications
You must be signed in to change notification settings - Fork 857
Expand file tree
/
Copy pathLoggingRedactionExtensions.cs
More file actions
60 lines (51 loc) · 2.28 KB
/
LoggingRedactionExtensions.cs
File metadata and controls
60 lines (51 loc) · 2.28 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Shared.Diagnostics;
namespace Microsoft.Extensions.Logging;
/// <summary>
/// Extensions for configuring logging redaction features.
/// </summary>
public static class LoggingRedactionExtensions
{
/// <summary>
/// Enables redaction functionality within the logging infrastructure.
/// </summary>
/// <param name="builder">The dependency injection container to add logging to.</param>
/// <returns>The value of <paramref name="builder"/>.</returns>
public static ILoggingBuilder EnableRedaction(this ILoggingBuilder builder)
=> EnableRedaction(builder, _ => { });
/// <summary>
/// Enables redaction functionality within the logging infrastructure.
/// </summary>
/// <param name="builder">The dependency injection container to add logging to.</param>
/// <param name="configure">Delegate the fine-tune the options.</param>
/// <returns>The value of <paramref name="builder"/>.</returns>
public static ILoggingBuilder EnableRedaction(this ILoggingBuilder builder, Action<LoggerRedactionOptions> configure)
{
_ = Throw.IfNull(builder);
_ = Throw.IfNull(configure);
_ = builder.Services
.AddExtendedLoggerFactory()
.Configure(configure);
return builder;
}
/// <summary>
/// Enables redaction functionality within the logging infrastructure.
/// </summary>
/// <param name="builder">The dependency injection container to add logging to.</param>
/// <param name="section">Configuration section that contains <see cref="LoggerRedactionOptions"/>.</param>
/// <returns>The value of <paramref name="builder"/>.</returns>
public static ILoggingBuilder EnableRedaction(this ILoggingBuilder builder, IConfigurationSection section)
{
_ = Throw.IfNull(builder);
_ = Throw.IfNull(section);
_ = builder.Services
.AddExtendedLoggerFactory()
.AddOptions<LoggerRedactionOptions>().Bind(section);
return builder;
}
}