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
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.rsuser
*.suo
*.user
*.userosscache
@@ -10,6 +13,9 @@
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Mono auto generated files
mono_crash.*
# Build results
[Dd]ebug/
[Dd]ebugPublic/
@@ -17,42 +23,62 @@
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
# Visual Studio 2015 cache/options directory
# Visual Studio 2015/2017 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# Visual Studio 2017 auto generated files
Generated\ Files/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
# NUnit
*.VisualState.xml
TestResult.xml
nunit-*.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
# Benchmark Results
BenchmarkDotNet.Artifacts/
# .NET Core
project.lock.json
project.fragment.lock.json
artifacts/
# ASP.NET Scaffolding
ScaffoldingReadMe.txt
# StyleCop
StyleCopReport.xml
# Files built by Visual Studio
*_i.c
*_p.c
*_i.h
*_h.h
*.ilk
*.meta
*.obj
*.iobj
*.pch
*.pdb
*.ipdb
*.pgc
*.pgd
*.rsp
@@ -62,6 +88,7 @@ artifacts/
*.tlh
*.tmp
*.tmp_proj
*_wpftmp.csproj
*.log
*.vspscc
*.vssscc
@@ -90,6 +117,9 @@ ipch/
*.vspx
*.sap
# Visual Studio Trace Files
*.e2e
# TFS 2012 Local Workspace
$tf/
@@ -101,15 +131,23 @@ _ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.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_*
.*crunch*.local.xml
@@ -141,9 +179,9 @@ publish/
# Publish Web Output
*.[Pp]ublish.xml
*.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
#*.pubxml
*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
@@ -153,13 +191,15 @@ PublishScripts/
# NuGet Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
**/[Pp]ackages/*
# 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
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets
@@ -176,12 +216,15 @@ AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
*.appx
*.appxbundle
*.appxupload
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
!?*.[Cc]ache/
# Others
ClientBin/
@@ -192,9 +235,12 @@ ClientBin/
*.jfm
*.pfx
*.publishsettings
node_modules/
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
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
@@ -209,15 +255,22 @@ _UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
ServiceFabricBackup/
*.rptproj.bak
# SQL Server files
*.mdf
*.ldf
*.ndf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
*.rptproj.rsuser
*- [Bb]ackup.rdl
*- [Bb]ackup ([0-9]).rdl
*- [Bb]ackup ([0-9][0-9]).rdl
# Microsoft Fakes
FakesAssemblies/
@@ -227,6 +280,7 @@ FakesAssemblies/
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
node_modules/
# Visual Studio 6 build log
*.plg
@@ -234,6 +288,9 @@ FakesAssemblies/
# Visual Studio 6 workspace options file
*.opt
# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
*.vbw
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
@@ -249,14 +306,55 @@ paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# CodeRush personal settings
.cr/personal
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.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": {
"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.Unionpay;
using PaySharp.Wechatpay;
using Serilog;
namespace PaySharp.Demo_Net_
{
@@ -17,6 +18,12 @@ namespace PaySharp.Demo_Net_
{
protected void Application_Start()
{
Log.Logger = new LoggerConfiguration()
.WriteTo.File($"{AppDomain.CurrentDomain.BaseDirectory}\\logs\\log.txt")
.Enrich.WithWebApiRouteTemplate()
.Enrich.WithWebApiActionName()
.CreateLogger();
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(a =>
{
@@ -60,6 +60,12 @@
<PackageReference Include="Microsoft.AspNet.WebPages.zh-Hans" Version="3.2.7" />
<PackageReference Include="Microsoft.Web.Infrastructure" Version="1.0.0.0" />
<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" />
</ItemGroup>
<ItemGroup>
+4
View File
@@ -74,6 +74,10 @@
<assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</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>
</runtime>
<system.webServer>
@@ -6,13 +6,15 @@ using System.Web.Mvc;
using PaySharp.Alipay.Response;
using PaySharp.Core;
using System.Threading.Tasks;
using Serilog;
namespace PaySharp.Demo.Controllers
{
public class NotifyController : Controller
{
private readonly ILogger _logger = Log.ForContext<NotifyController>();
private readonly IGateways _gateways;
private bool isRedirect;
private bool _isRedirect;
public NotifyController(IGateways gateways)
{
@@ -32,7 +34,7 @@ namespace PaySharp.Demo.Controllers
// 接收并处理支付通知
await notify.ReceivedAsync();
if (isRedirect)
if (_isRedirect)
{
Response.Redirect("https://github.com/Varorbc/PaySharp");
}
@@ -52,34 +54,44 @@ namespace PaySharp.Demo.Controllers
//同步通知,即浏览器跳转返回
if (e.NotifyType == NotifyType.Sync)
{
isRedirect = true;
_isRedirect = true;
}
}
_logger.Information(e.NotifyResponse.Raw);
//处理成功返回true
return true;
}
private bool Notify_RefundSucceed(object arg1, RefundSucceedEventArgs arg2)
{
_logger.Information(arg2.NotifyResponse.Raw);
// 订单退款时的处理代码
return true;
}
private bool Notify_CancelSucceed(object arg1, CancelSucceedEventArgs arg2)
{
_logger.Information(arg2.NotifyResponse.Raw);
// 订单撤销时的处理代码
return true;
}
private bool Notify_UnknownNotify(object sender, UnKnownNotifyEventArgs e)
{
_logger.Information(e.NotifyResponse.Raw);
// 未知时的处理代码
return true;
}
private void Notify_UnknownGateway(object sender, UnknownGatewayEventArgs e)
{
_logger.Information(e.NotifyResponse.Raw);
// 无法识别支付网关时的处理代码
}
}
@@ -4,6 +4,10 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\PaySharp.Alipay\PaySharp.Alipay.csproj" />
<ProjectReference Include="..\..\src\PaySharp.Allinpay\PaySharp.Allinpay.csproj" />
+26 -2
View File
@@ -1,5 +1,8 @@
using Microsoft.AspNetCore.Hosting;
using System;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Events;
namespace PaySharp.Demo
{
@@ -7,14 +10,35 @@ namespace PaySharp.Demo
{
public static void Main(string[] args)
{
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) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
})
.UseSerilog();
}
}
+1 -1
View File
@@ -604,7 +604,7 @@
</p>
<p>
<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>
<label>&nbsp;</label>