支付宝回调函数调试和加入日志已经linux的发布更新
1 支付宝只能调用外部网络
SetNotifyUrl()这就是支付宝能调用的外部网址
2新建一个Nlog.config (下面两个都行,只是路径不一样)
<?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="info"
throwException ="true"
internalLogFile="logs/internal-nlog.txt">
//日志的错误位置文件
<variable name="logDirectory" value="${basedir}/logs"/>
<!-- the targets to write to -->
<targets async="true">
<!-- write logs to file -->
<target xsi:type="File" name="allfile" fileName="${logDirectory}/nlog-all-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
<!-- another file log, only own logs. Uses some ASP.NET core renderers -->
<target xsi:type="File" name="ownFile-web" fileName="${logDirectory}/nlog-own-${shortdate}.log"
layout="${longdate}|${event-properties:item=EventId_Id}|${uppercase:${level}}|${logger}|${message} ${exception:format=tostring}" />
<!--|url: ${aspnet-request-url}|action: ${aspnet-mvc-action}-->
<!-- write log message to database -->
<!--<target name="db" xsi:type="AsyncWrapper" queueLimit="5000" overflowAction="Discard">-->
<!--target type="Database" name="db" dbProvider="Npgsql.NpgsqlConnection,Npgsql" 《这里的数据库名字注意查找》connectionString="Database=backofficev2;Host=*;User Id=*;Password=*;pooling=false;port=*;">
<commandText>
//使用postgresql 这里的字段要加双引号,timestamp要将string类型的转换为timestamp类型
INSERT INTO "SystemLog"("Source","Level","Content","CreatedAt") VALUES(@source, @level, @content, TO_TIMESTAMP(@createdAt, 'YYYY-MM-DD HH24:MI:SS'));
-->
<!--/commandText -->
<!-- database connection parameters ${logger} Server-->
<!--数据库中要写的字段->
<parameter name="@source" layout="Server" />
<parameter name="@level" layout="${level}" />
<parameter name="@content" layout="${message}" />
<parameter name="@createdAt" layout="${date}" />
</target>
</target>-->
</targets>
<!-- rules to map from logger name to target -->
<rules>
<!--TRACE,DEBUG,INFO,WARN,ERROR,FATAL警告级别控制-->
<logger name="*" minlevel="Trace" writeTo="allfile" />
<!--INFO,WARN,ERROR,FATAL-->
<logger name="AiEcgWebApi.Controllers.*" minlevel="Warn" writeTo="db" />
<!--DEBUG,INFO,WARN,ERROR,FATAL-->
<logger name="*" minlevel="Debug" writeTo="ownFile-web" />
</rules>
</nlog>
<?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" throwConfigExceptions="true" internalLogLevel="info" internalLogFile="E:\log\ISP\internal-nlog.txt"> <!--autoReload:修改后自动加载--> <!--throwConfigExceptions:NLog日志系统抛出异常--> <!--internalLogLevel:内部日志的级别--> <!--internalLogFile:内部日志保存路径,日志的内容大概就是NLog的版本信息,配置文件的地址等等--> <!-- the targets to write to --> <!--输出日志的配置,用于rules读取--> <targets> <!-- 将日志写入文件中 --> <target xsi:type="File" name="allfile" fileName="Logs/${shortdate}/ApiTracker.log" layout="${longdate}|${logger}|${uppercase:${level}}|${message} ${exception}" /> <target xsi:type="File" name="error" fileName="Logs/${shortdate}/ApiError.log" layout="${longdate}|${logger}|${uppercase:${level}}|${message} ${exception}" /> <target xsi:type="Null" name="blackhole" /> </targets> <!-- rules to map from logger name to target --> <rules> <!--路由顺序会对日志打印产生影响。路由匹配逻辑为顺序匹配。--> <!--All logs, including from Microsoft--> <logger name="*" minlevel="Trace" writeTo="allfile" /> <!--Skip Microsoft logs and so log only own logs--> <logger name="Microsoft.*" minlevel="Trace" writeTo="blackhole" final="true" /> <logger name="*" minlevel="Trace" writeTo="error" /> </rules> </nlog>
3nuget nlog包在startup中依赖注入
public void Configure( ILoggerFactory loggerFactory) { loggerFactory.AddNLog();//添加NLog loggerFactory.ConfigureNLog("Nlog.config"); }
4 在使用的地方依赖注入
public class xxxController : Controller { private readonly ILogger<xxxController> _logger; public xxxController(ILogger<xxxController> logger, ) { _logger = logger; }
//在具体的action中用_logger.LogError()或LogInformation等方法 }
5linux有空还是要学习一些一些基本的命令,做到可以在上面发布新项目以及修改,还有pm2的命令