日志面板是我在Github写的一个开源项目,旨在让查看日志变的方便快捷。在线预览 如今功能有日志检索、趋势图、异常堆栈快速查看、日志详情等 logdashboard支持自定义日志模型能够记录更多自定义的属性。 logdashboard支持的日志来源有如下两种,推荐在开发时使用文件源,部署生产环境时使用数据库源html
在部署时支持页面受权与自定义身份验证过滤器 更多介绍请参见官网git
确保机器上安装了DotNetCore SDK,打开PowerShell运行如下命令,咱们将建立一个AspNetCore空项目github
dotnet new empty
使用VSCode或VisualStudio打开项目,这时咱们还须要作一些其余的准备工做。日志组件选用Nlog数据库
Install-Package NLog.Web.AspNetCore
打开Program.cs在CreateWebHostBuilder方法中添加Nlog中间件,复制如下代码覆盖CreateWebHostBuilder方法浏览器
public static IWebHost CreateWebHostBuilder(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .ConfigureLogging(logging => { logging.ClearProviders(); logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Information); }) .UseNLog() .Build();
添加一个Nlog.config到项目中,并右键文件设置为复制到输出目录(始终复制),如下是Nlog.config的所有内容app
<?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" throwExceptions="false" internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log"> <variable name="myvar" value="myvalue"/> <targets> <target xsi:type="file" name="File" fileName="${basedir}/logs/${shortdate}.log" layout="${longdate}||${level}||${logger}||${message}||${exception:format=ToString:innerFormat=ToString:maxInnerExceptionLevel=10:separator=\r\n}||end" /> </targets> <rules> <logger name="*" minlevel="Debug" writeTo="file" /> </rules> </nlog>
准备工做已经结束,这时安装LogDashboardasync
Install-Package LogDashboard
打开Startup.cs咱们要作两件事ide
public void ConfigureServices(IServiceCollection services) { services.AddLogDashboard(); }
public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseLogDashboard(); app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); }); }
大功告成,这时运行项目,在浏览器中导航到/logdashboard。这时就能看到日志面板了ui
原文出处:https://www.cnblogs.com/LiangSW/p/10232684.htmlspa