-
-
Notifications
You must be signed in to change notification settings - Fork 131
/
Program.cs
94 lines (78 loc) · 3.43 KB
/
Program.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Diagnostics;
using System.Threading.Tasks;
using McMaster.Extensions.CommandLineUtils;
namespace DigApp
{
public class Program
{
public static async Task<int> Main(string[] args)
{
DnsClient.Tracing.Source.Switch.Level = SourceLevels.Warning;
DnsClient.Tracing.Source.Listeners.Add(new ConsoleTraceListener());
var app = new CommandLineApplication(throwOnUnexpectedArg: true);
try
{
_ = app.Command("perf", (perfApp) => _ = new PerfCommand(perfApp, args), throwOnUnexpectedArg: true);
_ = app.Command("random", (randApp) => _ = new RandomCommand(randApp, args), throwOnUnexpectedArg: true);
// Command must initialize so that it adds the configuration.
_ = new DigCommand(app, args);
return await app.ExecuteAsync(args).ConfigureAwait(false);
}
catch (UnrecognizedCommandParsingException ex)
{
Console.WriteLine(ex.Message);
app.ShowHelp();
}
catch (CommandParsingException ex)
{
Console.WriteLine(ex.Message);
app.ShowHelp();
}
catch (Exception ex)
{
Console.WriteLine(ex);
return 500;
}
return -1;
}
}
/* Example code to hook Microsoft.Extensions.Logging up with DnsClient */
////var services = new ServiceCollection();
////services.AddLogging(o =>
////{
//// o.AddConsole();
//// o.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
////});
////var provider = services.BuildServiceProvider();
////var factory = provider.GetRequiredService<Microsoft.Extensions.Logging.ILoggerFactory>();
////DnsClient.Logging.LoggerFactory = new LoggerFactoryWrapper(factory);
////internal class LoggerFactoryWrapper : DnsClient.Internal.ILoggerFactory
////{
//// private readonly Microsoft.Extensions.Logging.ILoggerFactory _microsoftLoggerFactory;
//// public LoggerFactoryWrapper(Microsoft.Extensions.Logging.ILoggerFactory microsoftLoggerFactory)
//// {
//// _microsoftLoggerFactory = microsoftLoggerFactory ?? throw new ArgumentNullException(nameof(microsoftLoggerFactory));
//// }
//// public DnsClient.Internal.ILogger CreateLogger(string categoryName)
//// {
//// return new DnsLogger(_microsoftLoggerFactory.CreateLogger(categoryName));
//// }
//// private class DnsLogger : DnsClient.Internal.ILogger
//// {
//// private readonly Microsoft.Extensions.Logging.ILogger _logger;
//// public DnsLogger(Microsoft.Extensions.Logging.ILogger logger)
//// {
//// _logger = logger ?? throw new ArgumentNullException(nameof(logger));
//// }
//// public bool IsEnabled(DnsClient.Internal.LogLevel logLevel)
//// {
//// return _logger.IsEnabled((Microsoft.Extensions.Logging.LogLevel)logLevel);
//// }
//// public void Log(DnsClient.Internal.LogLevel logLevel, int eventId, Exception exception, string message, params object[] args)
//// {
//// _logger.Log((Microsoft.Extensions.Logging.LogLevel)logLevel, eventId, exception, message, args);
//// }
//// }
////}
}