-
Notifications
You must be signed in to change notification settings - Fork 434
/
LoggingBuilder.cs
45 lines (38 loc) · 1.75 KB
/
LoggingBuilder.cs
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
using Azure.Functions.Cli.Common;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.Extensibility;
using Microsoft.ApplicationInsights.Extensibility.Implementation;
using Microsoft.Azure.WebJobs.Script;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Azure.Functions.Cli.Diagnostics
{
internal class LoggingBuilder : IConfigureBuilder<ILoggingBuilder>
{
private LoggingFilterHelper _loggingFilterHelper;
private readonly string _jsonOutputFile;
public LoggingBuilder(LoggingFilterHelper loggingFilterHelper, string jsonOutputFile)
{
_loggingFilterHelper = loggingFilterHelper;
_jsonOutputFile = jsonOutputFile;
}
public void Configure(ILoggingBuilder builder)
{
builder.Services.AddSingleton<ILoggerProvider>(p =>
{
//Cache LoggerFilterOptions to be used by the logger to filter logs based on content
var filterOptions = p.GetService<IOptions<LoggerFilterOptions>>();
return new ColoredConsoleLoggerProvider(_loggingFilterHelper, filterOptions.Value, _jsonOutputFile);
});
builder.AddFilter<ColoredConsoleLoggerProvider>((category, level) => true);
builder.Services.AddSingleton<TelemetryClient>(provider =>
{
TelemetryConfiguration configuration = provider.GetService<TelemetryConfiguration>();
TelemetryClient client = new TelemetryClient(configuration);
client.Context.GetInternalContext().SdkVersion = $"azurefunctionscoretools: {Constants.CliVersion}";
return client;
});
}
}
}