feat:添加日志模块
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
using AspNetCore.Microsoft.AspNetCore.Hosting;
|
||||
using NLog;
|
||||
using NLog.Extensions.Logging;
|
||||
using Yi.Framework.Core.Autofac.Extensions;
|
||||
using Yi.Framework.Core.Autofac.Modules;
|
||||
using Yi.Framework.Core.Extensions;
|
||||
using Yi.Framework.Core.Module;
|
||||
using Yi.Template.Application;
|
||||
using Yi.Template.Web;
|
||||
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
//配置日志
|
||||
builder.Services.AddLogging(builder => { builder.ClearProviders().AddNLog("nlog.config").SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); });
|
||||
Logger? _logger = LogManager.Setup().LoadConfigurationFromAssemblyResource(typeof(Program).Assembly).GetCurrentClassLogger();
|
||||
_logger.Info("-----( ¯ □ ¯ )YiFrameowrk框架启动-----");
|
||||
//设置启动url
|
||||
builder.WebHost.UseStartUrlsServer(builder.Configuration);
|
||||
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
<ProjectReference Include="..\Yi.Template.Sqlsugar\Yi.Template.Sqlsugar.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="key.pem">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
||||
@@ -1,12 +1,18 @@
|
||||
using AspNetCore.Microsoft.AspNetCore.Hosting;
|
||||
using NLog;
|
||||
using NLog.Extensions.Logging;
|
||||
using Yi.Framework.Core.Autofac.Extensions;
|
||||
using Yi.Framework.Core.Autofac.Modules;
|
||||
using Yi.Framework.Core.Extensions;
|
||||
using Yi.Framework.Core.Module;
|
||||
using Yi.Template.Application;
|
||||
using Yi.Template.Web;
|
||||
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
//配置日志
|
||||
builder.Services.AddLogging(builder => { builder.ClearProviders().AddNLog("nlog.config").SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace); });
|
||||
Logger? _logger = LogManager.Setup().LoadConfigurationFromAssemblyResource(typeof(Program).Assembly).GetCurrentClassLogger();
|
||||
_logger.Info("-----( ¯ □ ¯ )YiFrameowrk框架启动-----");
|
||||
//设置启动url
|
||||
builder.WebHost.UseStartUrlsServer(builder.Configuration);
|
||||
|
||||
|
||||
@@ -15,6 +15,12 @@
|
||||
<ProjectReference Include="..\Yi.Template.Sqlsugar\Yi.Template.Sqlsugar.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="key.pem">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?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">
|
||||
|
||||
<variable name="archiveAboveSize" value="10485760"/>
|
||||
<variable name="maxArchiveFiles" value="50"/>
|
||||
<variable name="layout" value="${date:format=HH\:mm\:ss.fff}|${level}|${threadId:format=threadId}|${logger}${newline}>>${message} ${exception:format=tostring}"/>
|
||||
<variable name="logsRootPath" value="${basedir}/logs/${shortdate}" />
|
||||
|
||||
<targets>
|
||||
<target xsi:type="File"
|
||||
name="AllFile"
|
||||
fileName="${logsRootPath}/AllFile/log.log"
|
||||
layout="${layout}${newline}"
|
||||
archiveAboveSize="${archiveAboveSize}"
|
||||
maxArchiveFiles="${maxArchiveFiles}" />
|
||||
|
||||
<target xsi:type="ColoredConsole"
|
||||
name="ColoredConsole"
|
||||
layout="${layout}${newline}">
|
||||
<highlight-row condition="level == LogLevel.Info" foregroundColor="White" />
|
||||
<highlight-row condition="level == LogLevel.Debug" foregroundColor="Green" />
|
||||
<highlight-row condition="level == LogLevel.Warn" foregroundColor="Yellow" />
|
||||
<highlight-row condition="level == LogLevel.Error" foregroundColor="Red" />
|
||||
<highlight-row condition="level == LogLevel.Fatal" foregroundColor="Red" backgroundColor="White" />
|
||||
</target>
|
||||
|
||||
<target xsi:type="File" name="OwnFile"
|
||||
fileName="${logsRootPath}/OwnFile/log.log"
|
||||
layout="${layout}|Url: ${aspnet-request-url}|Action: ${aspnet-mvc-action}${newline}"
|
||||
archiveAboveSize="${archiveAboveSize}"
|
||||
maxArchiveFiles="${maxArchiveFiles}" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="Quartz.*" maxlevel="Warn" final="true" />
|
||||
<logger name="Grpc.*" maxlevel="Debug" final="true" />
|
||||
<logger name="Grpc.*" maxlevel="Trace" final="true" />
|
||||
<logger name="Microsoft.EntityFrameworkCore.*" maxlevel="Warn" final="true" />
|
||||
<logger name="Microsoft.AspNetCore.*" maxlevel="Warn" final="true" />
|
||||
<logger name="Microsoft.AspNetCore.SignalR.*" maxlevel="Warn" final="true" />
|
||||
<logger name="*" minlevel="Trace" maxlevel="Fatal" writeTo="AllFile,ColoredConsole"/>
|
||||
<logger name="Microsoft.Hosting.Lifetime" minlevel="Info" writeTo="ColoredConsole,OwnFile" final="true" />
|
||||
<logger name="Microsoft.*" maxlevel="Info" final="true" />
|
||||
<logger name="*" minlevel="Trace" writeTo="OwnFile" />
|
||||
|
||||
</rules>
|
||||
</nlog>
|
||||
Reference in New Issue
Block a user