From d207747f392d71a481cb35b6d480a1578ecd03bf Mon Sep 17 00:00:00 2001 From: Jan Korf Date: Wed, 15 Dec 2021 22:08:57 +0100 Subject: [PATCH] NLog loggin docs --- Logging.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/Logging.md b/Logging.md index b101c5e..e5dc13a 100644 --- a/Logging.md +++ b/Logging.md @@ -122,5 +122,52 @@ public class BinanceDataProvider ```` +#### Console application +TODO + +### NLog +To make the CryptoExchange.Net logging write to the NLog logger you can use the following ways, depending on the type of project you're using. + +#### ASP.NET Core/Blazor + +With an ASP.Net Core or Blazor project, make sure to install the `NLog.Web.AspNetCore` package (https://github.com/NLog/NLog/wiki/Getting-started-with-ASP.NET-Core-5). +Adding `UseNLog` will add the NLog implementation as an ILogger which you can inject into implementations. Make sure you have a nlog.config configuration file in your project. + +*Configuring NLog as ILogger:* +````C# + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }) + .ConfigureLogging(logging => + { + logging.ClearProviders(); + logging.SetMinimumLevel(LogLevel.Trace); + }) + .UseNLog(); +```` + +*Injecting ILogger:* +````C# + +public class BinanceDataProvider +{ + BinanceClient _client; + + public BinanceDataProvider(ILogger logger) + { + _client = new BinanceClient(new BinanceClientOptions + { + LogLevel = LogLevel.Trace, + LogWriters = new List { logger } + }); + + } +} + +```` + #### Console application TODO \ No newline at end of file