THRIFT-4824 Logger deprecation warnings in tutorial
Client: netstd
Patch: Jens Geyer
this closes #1760
diff --git a/tutorial/netstd/Server/Program.cs b/tutorial/netstd/Server/Program.cs
index 1d9dd15..d27e90d 100644
--- a/tutorial/netstd/Server/Program.cs
+++ b/tutorial/netstd/Server/Program.cs
@@ -41,12 +41,17 @@
{
public class Program
{
- private static readonly ILogger Logger = new LoggerFactory().AddConsole(LogLevel.Trace).AddDebug(LogLevel.Trace).CreateLogger(nameof(Server));
+ private static ServiceCollection ServiceCollection = new ServiceCollection();
+ private static ILogger Logger;
public static void Main(string[] args)
{
args = args ?? new string[0];
+ ServiceCollection.AddLogging(logging => ConfigureLogging(logging));
+ Logger = ServiceCollection.BuildServiceProvider().GetService<ILoggerFactory>().CreateLogger(nameof(Server));
+
+
if (args.Any(x => x.StartsWith("-help", StringComparison.OrdinalIgnoreCase)))
{
DisplayHelp();
@@ -66,6 +71,13 @@
Logger.LogInformation("Server stopped");
}
+ private static void ConfigureLogging(ILoggingBuilder logging)
+ {
+ logging.SetMinimumLevel(LogLevel.Trace);
+ logging.AddConsole();
+ logging.AddDebug();
+ }
+
private static void DisplayHelp()
{
Logger.LogInformation(@"
@@ -131,12 +143,10 @@
private static async Task RunSelectedConfigurationAsync(Transport transport, Protocol protocol, CancellationToken cancellationToken)
{
- var fabric = new LoggerFactory().AddConsole(LogLevel.Trace).AddDebug(LogLevel.Trace);
var handler = new CalculatorAsyncHandler();
ITAsyncProcessor processor = null;
TServerTransport serverTransport = null;
-
switch (transport)
{
case Transport.Tcp:
@@ -209,6 +219,7 @@
Logger.LogInformation(
$"Selected TAsyncServer with {serverTransport} transport, {processor} processor and {inputProtocolFactory} protocol factories");
+ var fabric = ServiceCollection.BuildServiceProvider().GetService<ILoggerFactory>();
var server = new TSimpleAsyncServer(processor, serverTransport, inputProtocolFactory, outputProtocolFactory, fabric);
Logger.LogInformation("Starting the server...");
@@ -288,8 +299,11 @@
.UseUrls("http://localhost:9090")
.UseContentRoot(Directory.GetCurrentDirectory())
.UseStartup<Startup>()
+ .ConfigureLogging((ctx,logging) => ConfigureLogging(logging))
.Build();
+ Logger.LogTrace("test");
+ Logger.LogCritical("test");
host.RunAsync(cancellationToken).GetAwaiter().GetResult();
}
@@ -315,8 +329,7 @@
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env,
- ILoggerFactory loggerFactory)
+ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
app.UseMiddleware<THttpServerTransport>();
}