mirror of
https://github.com/JKorf/CryptoExchange.Net.git
synced 2026-08-11 16:32:57 +00:00
NLog loggin docs
+47
@@ -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<Startup>();
|
||||
})
|
||||
.ConfigureLogging(logging =>
|
||||
{
|
||||
logging.ClearProviders();
|
||||
logging.SetMinimumLevel(LogLevel.Trace);
|
||||
})
|
||||
.UseNLog();
|
||||
````
|
||||
|
||||
*Injecting ILogger:*
|
||||
````C#
|
||||
|
||||
public class BinanceDataProvider
|
||||
{
|
||||
BinanceClient _client;
|
||||
|
||||
public BinanceDataProvider(ILogger<BinanceDataProvider> logger)
|
||||
{
|
||||
_client = new BinanceClient(new BinanceClientOptions
|
||||
{
|
||||
LogLevel = LogLevel.Trace,
|
||||
LogWriters = new List<ILogger> { logger }
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
````
|
||||
|
||||
#### Console application
|
||||
TODO
|
||||
Reference in New Issue
Block a user