mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-23 06:38:50 +00:00
Logging (#1737)
* Logging * Doing dependency injection * expose GetLoggers for better testing Co-authored-by: stas <statis@microsoft.com>
This commit is contained in:
@ -1,17 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Azure.Functions.Worker.Configuration;
|
||||
using Azure.ResourceManager.Storage.Models;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Microsoft.OneFuzz.Service;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static List<ILog> GetLoggers() {
|
||||
List<ILog> loggers = new List<ILog>();
|
||||
foreach (var dest in EnvironmentVariables.LogDestinations)
|
||||
{
|
||||
loggers.Add(
|
||||
dest switch
|
||||
{
|
||||
LogDestination.AppInsights => new AppInsights(),
|
||||
LogDestination.Console => new Console(),
|
||||
_ => throw new Exception(string.Format("Unhandled Log Destination type: {0}", dest)),
|
||||
}
|
||||
);
|
||||
}
|
||||
return loggers;
|
||||
}
|
||||
|
||||
|
||||
public static void Main()
|
||||
{
|
||||
var host = new HostBuilder()
|
||||
.ConfigureFunctionsWorkerDefaults()
|
||||
.Build();
|
||||
.ConfigureFunctionsWorkerDefaults()
|
||||
.ConfigureServices((context, services) =>
|
||||
services.AddSingleton<LogTracerFactory>(_ => new LogTracerFactory(GetLoggers()))
|
||||
)
|
||||
.Build();
|
||||
|
||||
host.Run();
|
||||
}
|
||||
|
Reference in New Issue
Block a user