ASP.NET Core中使用NLog记录日志
2021-05-29 21:03
标签:oar log oge range 读取 row evel core xmlns 1:添加Nlog的组件 2:然后就是配置服务 3:配置文件nlog.config 4:记录输出 5:效果 ASP.NET Core中使用NLog记录日志 标签:oar log oge range 读取 row evel core xmlns 原文地址:https://www.cnblogs.com/ZkbFighting/p/14703489.html直接在NuGet里面搜索NLog.Web.AspNetCore
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
//public static IHostBuilder CreateHostBuilder(string[] args) =>
// Host.CreateDefaultBuilder(args)
// .ConfigureWebHostDefaults(webBuilder =>
// {
// webBuilder.UseStartup
xml version="1.0" encoding="utf-8" ?>
nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
autoReload="true"
throwConfigExceptions="true"
internalLogLevel="info"
internalLogFile="E:\log\internal-nlog.txt">
targets>
target xsi:type="File" name="allfile" fileName="D:\Log\nlog-all-${shortdate}.log"
layout="${longdate}|${logger}|${uppercase:${level}}|${message} ${exception}" />
target xsi:type="File" name="ownFile-web" fileName="D:\Log\nlog-my-${shortdate}.log"
layout="${longdate}|${logger}|${uppercase:${level}}|${message} ${exception}" />
target xsi:type="Null" name="blackhole" />
targets>
rules>
logger name="*" minlevel="Trace" writeTo="allfile" />
logger name="Microsoft.*" minlevel="Trace" final="true" />
logger name="*" minlevel="Trace" writeTo="ownFile-web" />
rules>
nlog>
[ApiController]
[Route("[controller]")]
public class WeatherForecastController : ControllerBase
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
private readonly ILogger
文章标题:ASP.NET Core中使用NLog记录日志
文章链接:http://soscw.com/index.php/essay/89265.html