增加 日志
This commit is contained in:
1 parent
ba5cb7b839
commit
c59096dfd1
7 files changed
+187
-12
No files matched your search
@@ -13,3 +13,4 @@ bin
|
||||
/Update/Update/*.user
|
||||
*.user
|
||||
IISProfile.pubxml
|
||||
*/**/logs
|
||||
@@ -576,10 +576,11 @@ namespace KJD_Web.BLL.WXXD
|
||||
{
|
||||
if (oem_id.IsNullOrEmpty())
|
||||
return 0;
|
||||
|
||||
LogHelper.Info($"找账号");
|
||||
// 1. 找到该oem下所有账户
|
||||
string sql = "SELECT user_name FROM wxxd.`user` WHERE oem_id='" + MysqlUtils.ReplaceSqlSpecial(oem_id) + "'";
|
||||
string sql = "SELECT user_name FROM `wxxd`.`user` WHERE oem_id='" + MysqlUtils.ReplaceSqlSpecial(oem_id) + "'";
|
||||
var userDt = mySql.ExecuteDataTable(sql);
|
||||
LogHelper.Info($"找账号:{sql}");
|
||||
if (!string.IsNullOrEmpty(mySql.Message) || userDt == null || userDt.Rows.Count == 0)
|
||||
return 0;
|
||||
|
||||
@@ -590,13 +591,15 @@ namespace KJD_Web.BLL.WXXD
|
||||
.ToList();
|
||||
if (userLst.Count == 0)
|
||||
return 0;
|
||||
|
||||
LogHelper.Info($"当前找到:{userLst.Count} 账号");
|
||||
// 2. 该oem所有账户的未结算流水,按id升序
|
||||
sql = "SELECT * FROM `wxxd`.`user_payment_record` WHERE user_name IN ('" + string.Join("','", userLst) + "') AND type IN (20,23,26,16,31) AND settlement=0 AND is_deleted=0 ORDER BY id ASC";
|
||||
LogHelper.Info($"流水SQL:{sql}");
|
||||
var flowDt = mySql.ExecuteDataTable(sql);
|
||||
LogHelper.Info($"找到:{flowDt?.Rows?.Count ?? 0}条");
|
||||
if (!string.IsNullOrEmpty(mySql.Message) || flowDt == null || flowDt.Rows.Count == 0)
|
||||
return 0;
|
||||
|
||||
LogHelper.Info($"开始计算");
|
||||
decimal total_amount = 0m; // 总金额(元)
|
||||
decimal rebate_amount = 0m; // 正数部分(累计返利)
|
||||
HashSet<string> deductedOrderSet = new HashSet<string>(); // type=23 已扣减的订单
|
||||
@@ -643,7 +646,7 @@ namespace KJD_Web.BLL.WXXD
|
||||
long total_fen = (long)Math.Round(total_amount * 100m);
|
||||
long rebate_fen = (long)Math.Round(rebate_amount * 100m);
|
||||
string now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
LogHelper.Info($"开始修改");
|
||||
// 3. 写oem金额 + 更新流水状态(同一事务)
|
||||
sql = "UPDATE wxxd.oem SET available_balance=available_balance+" + total_fen +
|
||||
", total_rebate_amount=total_rebate_amount+" + rebate_fen +
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
using System;
|
||||
using KJD_Web.Utils;
|
||||
using NLog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using System.Web.SessionState;
|
||||
using KJD_Web.Utils;
|
||||
|
||||
namespace KJD_Web
|
||||
{
|
||||
public class Global : System.Web.HttpApplication
|
||||
{
|
||||
|
||||
protected void Application_Start(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
protected void Application_Start(object sender, EventArgs e)
|
||||
{
|
||||
LogHelper.Info("应用程序启动");
|
||||
}
|
||||
|
||||
protected void Session_Start(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@@ -57,6 +57,9 @@
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\Dll\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="NLog, Version=6.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\NLog.6.2.0\lib\net46\NLog.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Web.DynamicData" />
|
||||
@@ -129,6 +132,7 @@
|
||||
<Compile Include="BLL\WXXD\WXShopManage.cs" />
|
||||
<Compile Include="BLL\WXXD\WXShopRevenueStatisticsManage.cs" />
|
||||
<Compile Include="BLL\WXXD\WXUserManage.cs" />
|
||||
<Compile Include="LogHelper.cs" />
|
||||
<Compile Include="Model\ErpModel\ErpMerchantInfo.cs" />
|
||||
<Compile Include="Model\JSTDownProdSkuInfo.cs" />
|
||||
<Compile Include="Model\PddModel\BuyerLoginInfo.cs" />
|
||||
@@ -298,6 +302,7 @@
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="Properties\PublishProfiles\IISProfile.pubxml" />
|
||||
<Content Include="Nlog.config" />
|
||||
<None Include="Web.Debug.config">
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</None>
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using NLog;
|
||||
|
||||
namespace KJD_Web
|
||||
{
|
||||
public static class LogHelper
|
||||
{
|
||||
private static Logger _logger;
|
||||
|
||||
// 静态构造函数,获取Logger实例
|
||||
static LogHelper()
|
||||
{
|
||||
_logger = LogManager.GetCurrentClassLogger();
|
||||
}
|
||||
|
||||
// 获取日志记录器
|
||||
public static Logger Logger
|
||||
{
|
||||
get { return _logger; }
|
||||
}
|
||||
|
||||
// 便捷方法:记录信息
|
||||
public static void Info(string message, params object[] args)
|
||||
{
|
||||
_logger.Info(message, args);
|
||||
}
|
||||
|
||||
// 便捷方法:记录错误
|
||||
public static void Error(string message, params object[] args)
|
||||
{
|
||||
_logger.Error(message, args);
|
||||
}
|
||||
|
||||
// 便捷方法:记录错误(含异常)
|
||||
public static void Error(Exception ex, string message = null, params object[] args)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message))
|
||||
_logger.Error(ex);
|
||||
else
|
||||
_logger.Error(ex, message, args);
|
||||
}
|
||||
|
||||
// 便捷方法:记录警告
|
||||
public static void Warn(string message, params object[] args)
|
||||
{
|
||||
_logger.Warn(message, args);
|
||||
}
|
||||
|
||||
// 便捷方法:记录调试
|
||||
public static void Debug(string message, params object[] args)
|
||||
{
|
||||
_logger.Debug(message, args);
|
||||
}
|
||||
|
||||
// 便捷方法:记录跟踪
|
||||
public static void Trace(string message, params object[] args)
|
||||
{
|
||||
_logger.Trace(message, args);
|
||||
}
|
||||
|
||||
// 记录方法进入(用于方法调用跟踪)
|
||||
public static void LogMethodEntry(string methodName, params object[] parameters)
|
||||
{
|
||||
if (_logger.IsTraceEnabled)
|
||||
{
|
||||
_logger.Trace("进入方法: {0} (参数: {1})", methodName,
|
||||
string.Join(", ", parameters));
|
||||
}
|
||||
}
|
||||
|
||||
// 记录方法退出
|
||||
public static void LogMethodExit(string methodName, object result = null)
|
||||
{
|
||||
if (_logger.IsTraceEnabled)
|
||||
{
|
||||
_logger.Trace("退出方法: {0} (返回值: {1})", methodName, result ?? "void");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?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="Info"
|
||||
internalLogFile="c:\temp\nlog-internal.log">
|
||||
|
||||
<!-- 启用.net core的核心布局渲染器(传统ASP.NET使用NLog.Web) -->
|
||||
<extensions>
|
||||
<!-- 如果是ASP.NET Core项目使用这个 -->
|
||||
<!-- <add assembly="NLog.Web.AspNetCore" /> -->
|
||||
|
||||
<!-- 如果是传统ASP.NET Web Forms/Web Service使用这个 -->
|
||||
<add assembly="NLog.Web" />
|
||||
</extensions>
|
||||
|
||||
<!-- 写入日志的目标配置 -->
|
||||
<targets>
|
||||
<!-- 致命错误 - 单独文件 -->
|
||||
<target xsi:type="File" name="fatal"
|
||||
fileName="logs/${date:format=yyyyMM}/Fatal/${shortdate}.log"
|
||||
layout="${longdate}|${level:uppercase=true}|${logger}|${callsite}|${message}|${exception:format=tostring}"
|
||||
archiveEvery="Day"
|
||||
maxArchiveFiles="30"
|
||||
concurrentWrites="true" />
|
||||
|
||||
<!-- 错误日志 -->
|
||||
<target xsi:type="File" name="error"
|
||||
fileName="logs/${date:format=yyyyMM}/Error/${shortdate}.log"
|
||||
layout="${longdate}|${level:uppercase=true}|${logger}|${callsite}|${message}|${exception:format=tostring}"
|
||||
archiveEvery="Day"
|
||||
maxArchiveFiles="30"
|
||||
concurrentWrites="true" />
|
||||
|
||||
<!-- 警告日志 -->
|
||||
<target xsi:type="File" name="warn"
|
||||
fileName="logs/${date:format=yyyyMM}/Warn/${shortdate}.log"
|
||||
layout="${longdate}|${level:uppercase=true}|${logger}|${callsite}|${message}|${exception:format=tostring}"
|
||||
archiveEvery="Day"
|
||||
maxArchiveFiles="30"
|
||||
concurrentWrites="true" />
|
||||
|
||||
<!-- 信息日志 -->
|
||||
<target xsi:type="File" name="info"
|
||||
fileName="logs/${date:format=yyyyMM}/Info/${shortdate}.log"
|
||||
layout="${longdate}|${level:uppercase=true}|${logger}|${callsite}|${message}|${exception:format=tostring}"
|
||||
archiveEvery="Day"
|
||||
maxArchiveFiles="30"
|
||||
concurrentWrites="true" />
|
||||
|
||||
<!-- 调试日志 -->
|
||||
<target xsi:type="File" name="debug"
|
||||
fileName="logs/${date:format=yyyyMM}/Debug/${shortdate}.log"
|
||||
layout="${longdate}|${level:uppercase=true}|${logger}|${callsite}|${message}|${exception:format=tostring}"
|
||||
archiveEvery="Day"
|
||||
maxArchiveFiles="7"
|
||||
concurrentWrites="true" />
|
||||
|
||||
<!-- 控制台输出(调试用) -->
|
||||
<target xsi:type="Console" name="console"
|
||||
layout="${longdate}|${level:uppercase=true}|${logger}|${message}" />
|
||||
</targets>
|
||||
|
||||
<!-- 映射规则 -->
|
||||
<rules>
|
||||
<!-- 规则1: 调试级别(Trace, Debug)写入debug文件 -->
|
||||
<logger name="*" minlevel="Trace" maxlevel="Debug" writeTo="debug,console" />
|
||||
|
||||
<!-- 规则2: 跳过微软框架的Info级别以下日志(减少噪音) -->
|
||||
<logger name="Microsoft.*" maxlevel="Info" final="true" />
|
||||
|
||||
<!-- 规则3: 信息级别(Info, Warn)写入info和warn文件 -->
|
||||
<logger name="*" level="Info" writeTo="info" />
|
||||
<logger name="*" level="Warn" writeTo="warn" />
|
||||
<!-- 或者合并为一行:<logger name="*" minlevel="Info" maxlevel="Warn" writeTo="info,warn" /> -->
|
||||
|
||||
<!-- 规则4: 错误级别(Error, Fatal)写入error和fatal文件 -->
|
||||
<logger name="*" level="Error" writeTo="error" />
|
||||
<logger name="*" level="Fatal" writeTo="fatal,error" />
|
||||
|
||||
<!-- 如果需要,也可以将所有级别都记录到同一个文件 -->
|
||||
<!-- <logger name="*" minlevel="Trace" writeTo="all" /> -->
|
||||
</rules>
|
||||
</nlog>
|
||||
@@ -1,4 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net46" />
|
||||
<package id="NLog" version="6.2.0" targetFramework="net462" />
|
||||
</packages>
|
||||
Reference in new issue
Block a user