Showing posts with the label Postgresql

Aspetcore: NLog with Postgresql

This Article is base ASP.Net Core 2 and the latest version of Nlog.

1. Install NLog and the Postgresql Package Using NuGet to install the package into your ASP.NET Core project: PM > Install-Package NLog.Web.AspNetCorePM > Install-Package Npgsql3. Register NLog Add in your Startup.cs  publicvoidConfigure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { ... env.ConfigureNLog("nlog.config"); ... // make sure Chinese chars don't fk up Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); //add NLog to ASP.NET Core loggerFactory.AddNLog(); //add NLog.Web app.AddNLogWeb(); }4. Add to Your Controller Add a logger object to your Controller. private readonly ILogger<YourController> _logger; Modify the constructor to use it publicYourController(ILogger<YourController> logger = null) { if (null != logger) { _logger = logger; } }5. Use Logging APIs Now, you can use the loggin…