demo中添加日志

This commit is contained in:
Varorbc
2020-07-01 13:45:00 +08:00
parent df5db1ae55
commit b8f737e258
9 changed files with 187 additions and 31 deletions
+120 -22
View File
@@ -1,7 +1,10 @@
## Ignore Visual Studio temporary files, build results, and ## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons. ## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files # User-specific files
*.rsuser
*.suo *.suo
*.user *.user
*.userosscache *.userosscache
@@ -10,6 +13,9 @@
# User-specific files (MonoDevelop/Xamarin Studio) # User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs *.userprefs
# Mono auto generated files
mono_crash.*
# Build results # Build results
[Dd]ebug/ [Dd]ebug/
[Dd]ebugPublic/ [Dd]ebugPublic/
@@ -17,42 +23,62 @@
[Rr]eleases/ [Rr]eleases/
x64/ x64/
x86/ x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/ bld/
[Bb]in/ [Bb]in/
[Oo]bj/ [Oo]bj/
[Ll]og/ [Ll]og/
[Ll]ogs/
# Visual Studio 2015 cache/options directory # Visual Studio 2015/2017 cache/options directory
.vs/ .vs/
# Uncomment if you have tasks that create the project's static files in wwwroot # Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/ #wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results # MSTest test Results
[Tt]est[Rr]esult*/ [Tt]est[Rr]esult*/
[Bb]uild[Ll]og.* [Bb]uild[Ll]og.*
# NUNIT # NUnit
*.VisualState.xml *.VisualState.xml
TestResult.xml TestResult.xml
nunit-*.xml
# Build Results of an ATL Project # Build Results of an ATL Project
[Dd]ebugPS/ [Dd]ebugPS/
[Rr]eleasePS/ [Rr]eleasePS/
dlldata.c dlldata.c
# DNX # Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json project.lock.json
project.fragment.lock.json project.fragment.lock.json
artifacts/ artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c *_i.c
*_p.c *_p.c
*_i.h *_h.h
*.ilk *.ilk
*.meta *.meta
*.obj *.obj
*.iobj
*.pch *.pch
*.pdb *.pdb
*.ipdb
*.pgc *.pgc
*.pgd *.pgd
*.rsp *.rsp
@@ -62,6 +88,7 @@ artifacts/
*.tlh *.tlh
*.tmp *.tmp
*.tmp_proj *.tmp_proj
*_wpftmp.csproj
*.log *.log
*.vspscc *.vspscc
*.vssscc *.vssscc
@@ -90,6 +117,9 @@ ipch/
*.vspx *.vspx
*.sap *.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace # TFS 2012 Local Workspace
$tf/ $tf/
@@ -101,15 +131,23 @@ _ReSharper*/
*.[Rr]e[Ss]harper *.[Rr]e[Ss]harper
*.DotSettings.user *.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in # TeamCity is a build add-in
_TeamCity* _TeamCity*
# DotCover is a Code Coverage Tool # DotCover is a Code Coverage Tool
*.dotCover *.dotCover
# AxoCover is a Code Coverage Tool
.axoCover/*
!.axoCover/settings.json
# Coverlet is a free, cross platform Code Coverage Tool
coverage*[.json, .xml, .info]
# Visual Studio code coverage results
*.coverage
*.coveragexml
# NCrunch # NCrunch
_NCrunch_* _NCrunch_*
.*crunch*.local.xml .*crunch*.local.xml
@@ -141,9 +179,9 @@ publish/
# Publish Web Output # Publish Web Output
*.[Pp]ublish.xml *.[Pp]ublish.xml
*.azurePubxml *.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings # Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted # but database connection strings (with potential passwords) will be unencrypted
#*.pubxml *.pubxml
*.publishproj *.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to # Microsoft Azure Web App publish settings. Comment the next line if you want to
@@ -153,13 +191,15 @@ PublishScripts/
# NuGet Packages # NuGet Packages
*.nupkg *.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore # The packages folder can be ignored because of Package Restore
**/packages/* **/[Pp]ackages/*
# except build/, which is used as an MSBuild target. # except build/, which is used as an MSBuild target.
!**/packages/build/ !**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed # Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config #!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignoreable files # NuGet v3's project.json files produces more ignorable files
*.nuget.props *.nuget.props
*.nuget.targets *.nuget.targets
@@ -176,12 +216,15 @@ AppPackages/
BundleArtifacts/ BundleArtifacts/
Package.StoreAssociation.xml Package.StoreAssociation.xml
_pkginfo.txt _pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files # Visual Studio cache files
# files ending in .cache can be ignored # files ending in .cache can be ignored
*.[Cc]ache *.[Cc]ache
# but keep track of directories ending in .cache # but keep track of directories ending in .cache
!*.[Cc]ache/ !?*.[Cc]ache/
# Others # Others
ClientBin/ ClientBin/
@@ -192,9 +235,12 @@ ClientBin/
*.jfm *.jfm
*.pfx *.pfx
*.publishsettings *.publishsettings
node_modules/
orleans.codegen.cs orleans.codegen.cs
# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)
#*.snk
# Since there are multiple workflows, uncomment next line to ignore bower_components # Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/ #bower_components/
@@ -209,15 +255,22 @@ _UpgradeReport_Files/
Backup*/ Backup*/
UpgradeLog*.XML UpgradeLog*.XML
UpgradeLog*.htm UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files # SQL Server files
*.mdf *.mdf
*.ldf *.ldf
*.ndf
# Business Intelligence projects # Business Intelligence projects
*.rdl.data *.rdl.data
*.bim.layout *.bim.layout
*.bim_*.settings *.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes # Microsoft Fakes
FakesAssemblies/ FakesAssemblies/
@@ -227,6 +280,7 @@ FakesAssemblies/
# Node.js Tools for Visual Studio # Node.js Tools for Visual Studio
.ntvs_analysis.dat .ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log # Visual Studio 6 build log
*.plg *.plg
@@ -234,6 +288,9 @@ FakesAssemblies/
# Visual Studio 6 workspace options file # Visual Studio 6 workspace options file
*.opt *.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output # Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts **/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts **/*.DesktopClient/GeneratedArtifacts
@@ -249,14 +306,55 @@ paket-files/
# FAKE - F# Make # FAKE - F# Make
.fake/ .fake/
# JetBrains Rider # CodeRush personal settings
.idea/ .cr/personal
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS) # Python Tools for Visual Studio (PTVS)
__pycache__/ __pycache__/
*.pyc *.pyc
/publish.bat
# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config
# Tabs Studio
*.tss
# Telerik's JustMock configuration file
*.jmconfig
# BizTalk build output
*.btp.cs
*.btm.cs
*.odx.cs
*.xsd.cs
# OpenCover UI analysis results
OpenCover/
# Azure Stream Analytics local run output
ASALocalRun/
# MSBuild Binary and Structured Log
*.binlog
# NVidia Nsight GPU debugger configuration file
*.nvuser
# MFractors (Xamarin productivity tool) working folder
.mfractor/
# Local History for Visual Studio
.localhistory/
# BeatPulse healthcheck temp database
healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
# Fody - auto-generated XML schema
FodyWeavers.xsd
+2 -1
View File
@@ -1,5 +1,6 @@
{ {
"sdk": { "sdk": {
"version": "3.1.100" "version": "3.1.200",
"rollForward": "latestMinor"
} }
} }
+7
View File
@@ -10,6 +10,7 @@ using PaySharp.Core;
using PaySharp.Core.Mvc; using PaySharp.Core.Mvc;
using PaySharp.Unionpay; using PaySharp.Unionpay;
using PaySharp.Wechatpay; using PaySharp.Wechatpay;
using Serilog;
namespace PaySharp.Demo_Net_ namespace PaySharp.Demo_Net_
{ {
@@ -17,6 +18,12 @@ namespace PaySharp.Demo_Net_
{ {
protected void Application_Start() protected void Application_Start()
{ {
Log.Logger = new LoggerConfiguration()
.WriteTo.File($"{AppDomain.CurrentDomain.BaseDirectory}\\logs\\log.txt")
.Enrich.WithWebApiRouteTemplate()
.Enrich.WithWebApiActionName()
.CreateLogger();
AreaRegistration.RegisterAllAreas(); AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(a => GlobalConfiguration.Configure(a =>
{ {
@@ -60,6 +60,12 @@
<PackageReference Include="Microsoft.AspNet.WebPages.zh-Hans" Version="3.2.7" /> <PackageReference Include="Microsoft.AspNet.WebPages.zh-Hans" Version="3.2.7" />
<PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0.0" /> <PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Serilog.Sinks.File">
<Version>4.1.0</Version>
</PackageReference>
<PackageReference Include="SerilogWeb.Classic.WebApi">
<Version>4.0.5</Version>
</PackageReference>
<PackageReference Include="WebGrease" Version="1.6.0" /> <PackageReference Include="WebGrease" Version="1.6.0" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
+4
View File
@@ -74,6 +74,10 @@
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" /> <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" /> <bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</dependentAssembly> </dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Web.Http.WebHost" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>
<system.webServer> <system.webServer>
@@ -6,13 +6,15 @@ using System.Web.Mvc;
using PaySharp.Alipay.Response; using PaySharp.Alipay.Response;
using PaySharp.Core; using PaySharp.Core;
using System.Threading.Tasks; using System.Threading.Tasks;
using Serilog;
namespace PaySharp.Demo.Controllers namespace PaySharp.Demo.Controllers
{ {
public class NotifyController : Controller public class NotifyController : Controller
{ {
private readonly ILogger _logger = Log.ForContext<NotifyController>();
private readonly IGateways _gateways; private readonly IGateways _gateways;
private bool isRedirect; private bool _isRedirect;
public NotifyController(IGateways gateways) public NotifyController(IGateways gateways)
{ {
@@ -32,7 +34,7 @@ namespace PaySharp.Demo.Controllers
// 接收并处理支付通知 // 接收并处理支付通知
await notify.ReceivedAsync(); await notify.ReceivedAsync();
if (isRedirect) if (_isRedirect)
{ {
Response.Redirect("https://github.com/Varorbc/PaySharp"); Response.Redirect("https://github.com/Varorbc/PaySharp");
} }
@@ -52,34 +54,44 @@ namespace PaySharp.Demo.Controllers
//同步通知,即浏览器跳转返回 //同步通知,即浏览器跳转返回
if (e.NotifyType == NotifyType.Sync) if (e.NotifyType == NotifyType.Sync)
{ {
isRedirect = true; _isRedirect = true;
} }
} }
_logger.Information(e.NotifyResponse.Raw);
//处理成功返回true //处理成功返回true
return true; return true;
} }
private bool Notify_RefundSucceed(object arg1, RefundSucceedEventArgs arg2) private bool Notify_RefundSucceed(object arg1, RefundSucceedEventArgs arg2)
{ {
_logger.Information(arg2.NotifyResponse.Raw);
// 订单退款时的处理代码 // 订单退款时的处理代码
return true; return true;
} }
private bool Notify_CancelSucceed(object arg1, CancelSucceedEventArgs arg2) private bool Notify_CancelSucceed(object arg1, CancelSucceedEventArgs arg2)
{ {
_logger.Information(arg2.NotifyResponse.Raw);
// 订单撤销时的处理代码 // 订单撤销时的处理代码
return true; return true;
} }
private bool Notify_UnknownNotify(object sender, UnKnownNotifyEventArgs e) private bool Notify_UnknownNotify(object sender, UnKnownNotifyEventArgs e)
{ {
_logger.Information(e.NotifyResponse.Raw);
// 未知时的处理代码 // 未知时的处理代码
return true; return true;
} }
private void Notify_UnknownGateway(object sender, UnknownGatewayEventArgs e) private void Notify_UnknownGateway(object sender, UnknownGatewayEventArgs e)
{ {
_logger.Information(e.NotifyResponse.Raw);
// 无法识别支付网关时的处理代码 // 无法识别支付网关时的处理代码
} }
} }
@@ -4,6 +4,10 @@
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\PaySharp.Alipay\PaySharp.Alipay.csproj" /> <ProjectReference Include="..\..\src\PaySharp.Alipay\PaySharp.Alipay.csproj" />
<ProjectReference Include="..\..\src\PaySharp.Allinpay\PaySharp.Allinpay.csproj" /> <ProjectReference Include="..\..\src\PaySharp.Allinpay\PaySharp.Allinpay.csproj" />
+27 -3
View File
@@ -1,5 +1,8 @@
using Microsoft.AspNetCore.Hosting; using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
namespace PaySharp.Demo namespace PaySharp.Demo
{ {
@@ -7,7 +10,27 @@ namespace PaySharp.Demo
{ {
public static void Main(string[] args) public static void Main(string[] args)
{ {
CreateHostBuilder(args).Build().Run(); Log.Logger = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.File("logs\\log.txt")
.CreateLogger();
try
{
Log.Information("Starting web host");
CreateHostBuilder(args).Build().Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Host terminated unexpectedly");
}
finally
{
Log.CloseAndFlush();
}
} }
public static IHostBuilder CreateHostBuilder(string[] args) => public static IHostBuilder CreateHostBuilder(string[] args) =>
@@ -15,6 +38,7 @@ namespace PaySharp.Demo
.ConfigureWebHostDefaults(webBuilder => .ConfigureWebHostDefaults(webBuilder =>
{ {
webBuilder.UseStartup<Startup>(); webBuilder.UseStartup<Startup>();
}); })
.UseSerilog();
} }
} }
+1 -1
View File
@@ -604,7 +604,7 @@
</p> </p>
<p> <p>
<label>场景信息:</label> <label>场景信息:</label>
<input type="text" name="scene_info" value="{'h5_info': {'type':'Wap','wap_url': 'https://pay.qq.com','wap_name': '腾讯充值'}}"> <input type="text" name="scene_info" value="{&quot;h5_info&quot;:{&quot;type&quot;:&quot;Wap&quot;,&quot;wap_url&quot;:&quot;https://pay.qq.com&quot;,&quot;wap_name&quot;:&quot;腾讯充值&quot;}}">
</p> </p>
<p> <p>
<label>&nbsp;</label> <label>&nbsp;</label>