@@ -1,5 +1,6 @@ | |||||
using Microsoft.AspNetCore; | using Microsoft.AspNetCore; | ||||
using Microsoft.AspNetCore.Hosting; | using Microsoft.AspNetCore.Hosting; | ||||
using NLog.Web; | |||||
namespace Sample.Kafka.MySql | namespace Sample.Kafka.MySql | ||||
{ | { | ||||
@@ -14,7 +15,11 @@ namespace Sample.Kafka.MySql | |||||
public static IWebHost BuildWebHost(string[] args) => | public static IWebHost BuildWebHost(string[] args) => | ||||
WebHost.CreateDefaultBuilder(args) | WebHost.CreateDefaultBuilder(args) | ||||
.UseStartup<Startup>() | .UseStartup<Startup>() | ||||
.ConfigureLogging((hostingContext, builder) => | |||||
{ | |||||
hostingContext.HostingEnvironment.ConfigureNLog("nlog.config"); | |||||
}) | |||||
.UseNLog() | |||||
.Build(); | .Build(); | ||||
} | } | ||||
} | } |
@@ -10,6 +10,7 @@ | |||||
<ItemGroup> | <ItemGroup> | ||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" /> | <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.6" /> | ||||
<PackageReference Include="MySqlConnector" Version="0.38.0" /> | <PackageReference Include="MySqlConnector" Version="0.38.0" /> | ||||
<PackageReference Include="NLog.Web.AspNetCore" Version="4.5.2" /> | |||||
<PackageReference Include="zipkin4net" Version="1.2.0" /> | <PackageReference Include="zipkin4net" Version="1.2.0" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -20,5 +21,10 @@ | |||||
<ProjectReference Include="..\..\src\DotNetCore.CAP.MySql\DotNetCore.CAP.MySql.csproj" /> | <ProjectReference Include="..\..\src\DotNetCore.CAP.MySql\DotNetCore.CAP.MySql.csproj" /> | ||||
<ProjectReference Include="..\..\src\DotNetCore.CAP\DotNetCore.CAP.csproj" /> | <ProjectReference Include="..\..\src\DotNetCore.CAP\DotNetCore.CAP.csproj" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | |||||
<Content Update="nlog.config"> | |||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | |||||
</Content> | |||||
</ItemGroup> | |||||
</Project> | </Project> |
@@ -1,5 +1,4 @@ | |||||
using System; | |||||
using Microsoft.AspNetCore.Builder; | |||||
using Microsoft.AspNetCore.Builder; | |||||
using Microsoft.Extensions.DependencyInjection; | using Microsoft.Extensions.DependencyInjection; | ||||
namespace Sample.Kafka.MySql | namespace Sample.Kafka.MySql | ||||
@@ -0,0 +1,26 @@ | |||||
<?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" | |||||
internalLogLevel="Warn" | |||||
internalLogFile="logs/internal-nlog.txt"> | |||||
<variable name="myLogLayout" | |||||
value="---------------------------------------------------------------------------${newline}日期:${longdate} 级别:${uppercase:${level}} 用户:${aspnet-user-identity}(${aspnet-request-ip}) 记录器:${logger} ${newline}URL:${aspnet-request-method} ${aspnet-request-url:IncludePort=true:IncludeQueryString=true} ${newline}Action:${aspnet-mvc-action} ${newline}Message:${message} ${newline}${onexception:Exception:${exception:format=toString}}" /> | |||||
<extensions> | |||||
<add assembly="NLog.Web.AspNetCore" /> | |||||
</extensions> | |||||
<!-- define various log targets --> | |||||
<targets> | |||||
<!-- write logs to file --> | |||||
<target name="allfile" xsi:type="File" fileName="logs/cap-all-${shortdate}.log" | |||||
layout="${myLogLayout}" /> | |||||
</targets> | |||||
<rules> | |||||
<!--All logs, including from Microsoft--> | |||||
<logger name="*" minlevel="Debug" writeTo="allfile" /> | |||||
</rules> | |||||
</nlog> |