mirror of
https://github.com/project-redbud/FunGame-Core.git
synced 2025-04-22 03:59:35 +08:00
添加写错误日志的工具方法;修改根据格式获取日期字符串的方法 (#71)
This commit is contained in:
parent
3290278df4
commit
db6b01afa5
@ -209,7 +209,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
public static DateTime GetDateTime(TimeType type)
|
public static DateTime GetDateTime(TimeType type)
|
||||||
{
|
{
|
||||||
DateTime now = DateTime.Now;
|
DateTime now = DateTime.Now;
|
||||||
if (type == TimeType.DateOnly)
|
if (type == TimeType.LongDateOnly || type == TimeType.ShortDateOnly)
|
||||||
return now.Date;
|
return now.Date;
|
||||||
else return now;
|
else return now;
|
||||||
}
|
}
|
||||||
@ -221,8 +221,7 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
/// <returns>转换失败返回当前时间</returns>
|
/// <returns>转换失败返回当前时间</returns>
|
||||||
public static DateTime GetDateTime(string format)
|
public static DateTime GetDateTime(string format)
|
||||||
{
|
{
|
||||||
DateTime dt = default;
|
if (DateTime.TryParse(format, out DateTime dt))
|
||||||
if (DateTime.TryParse(format, out dt))
|
|
||||||
{
|
{
|
||||||
return dt;
|
return dt;
|
||||||
}
|
}
|
||||||
@ -242,8 +241,10 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
DateTime now = DateTime.Now;
|
DateTime now = DateTime.Now;
|
||||||
return type switch
|
return type switch
|
||||||
{
|
{
|
||||||
TimeType.DateOnly => now.Date.ToString("D"),
|
TimeType.LongDateOnly => now.Date.ToString("D"),
|
||||||
TimeType.TimeOnly => now.ToString("T"),
|
TimeType.ShortDateOnly => now.Date.ToString("d"),
|
||||||
|
TimeType.LongTimeOnly => now.ToString("T"),
|
||||||
|
TimeType.ShortTimeOnly => now.ToString("t"),
|
||||||
TimeType.Year4 => now.Year.ToString(),
|
TimeType.Year4 => now.Year.ToString(),
|
||||||
TimeType.Year2 => "'" + now.ToString("yy"),
|
TimeType.Year2 => "'" + now.ToString("yy"),
|
||||||
TimeType.Month => now.Month.ToString(),
|
TimeType.Month => now.Month.ToString(),
|
||||||
@ -256,9 +257,16 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取系统短日期
|
/// 获取系统时间并转为字符串
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="format">格式化字符串</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
public static string GetDateTimeToString(string format) => DateTime.Now.ToString(format);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取系统短时间
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>时:分:秒</returns>
|
||||||
public static string GetNowShortTime()
|
public static string GetNowShortTime()
|
||||||
{
|
{
|
||||||
DateTime now = DateTime.Now;
|
DateTime now = DateTime.Now;
|
||||||
@ -421,8 +429,8 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
private static string LetterVerifyCode(int length)
|
private static string LetterVerifyCode(int length)
|
||||||
{
|
{
|
||||||
char[] Verification = new char[length];
|
char[] Verification = new char[length];
|
||||||
char[] Dictionary = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
char[] Dictionary = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' ];
|
||||||
Random random = new();
|
Random random = new();
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
@ -439,10 +447,10 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
private static string MixVerifyCode(int length)
|
private static string MixVerifyCode(int length)
|
||||||
{
|
{
|
||||||
char[] Verification = new char[length];
|
char[] Verification = new char[length];
|
||||||
char[] Dictionary = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
char[] Dictionary = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
|
||||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
|
||||||
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
|
||||||
};
|
];
|
||||||
Random random = new();
|
Random random = new();
|
||||||
for (int i = 0; i < length; i++)
|
for (int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
|
@ -152,5 +152,33 @@ namespace Milimoe.FunGame.Core.Api.Utility
|
|||||||
}
|
}
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 写入TXT文件内容(如不存在文件会创建,反之新起一行追加)
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="message"></param>
|
||||||
|
/// <param name="filename">文件名</param>
|
||||||
|
/// <param name="path">相对路径</param>
|
||||||
|
/// <returns>内容</returns>
|
||||||
|
public static void WriteTXT(string message, string filename, string path = "")
|
||||||
|
{
|
||||||
|
if (path.Trim() != "")
|
||||||
|
{
|
||||||
|
// 不存在文件夹将创建文件夹
|
||||||
|
if (!Directory.Exists(path)) Directory.CreateDirectory(path);
|
||||||
|
path = Path.Combine(path, filename);
|
||||||
|
}
|
||||||
|
else path = $@"{Environment.CurrentDirectory}\{filename}";
|
||||||
|
// 写入内容
|
||||||
|
StreamWriter writer = File.Exists(path) ? new(path, true, General.DefaultEncoding) : new(path, false, General.DefaultEncoding);
|
||||||
|
writer.WriteLine(message);
|
||||||
|
writer.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 追加错误日志 默认写入logs文件夹下的当日日期.log文件
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="msg"></param>
|
||||||
|
public static void AppendErrorLog(string msg) => WriteTXT(DateTimeUtility.GetDateTimeToString(TimeType.General) + ": " + msg + "\r\n", DateTimeUtility.GetDateTimeToString("yyyy-MM-dd") + ".log", "logs");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -548,11 +548,18 @@
|
|||||||
<param name="type">格式化类型</param>
|
<param name="type">格式化类型</param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Milimoe.FunGame.Core.Api.Utility.DateTimeUtility.GetDateTimeToString(System.String)">
|
||||||
|
<summary>
|
||||||
|
获取系统时间并转为字符串
|
||||||
|
</summary>
|
||||||
|
<param name="format">格式化字符串</param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="M:Milimoe.FunGame.Core.Api.Utility.DateTimeUtility.GetNowShortTime">
|
<member name="M:Milimoe.FunGame.Core.Api.Utility.DateTimeUtility.GetNowShortTime">
|
||||||
<summary>
|
<summary>
|
||||||
获取系统短日期
|
获取系统短时间
|
||||||
</summary>
|
</summary>
|
||||||
<returns></returns>
|
<returns>时:分:秒</returns>
|
||||||
</member>
|
</member>
|
||||||
<member name="M:Milimoe.FunGame.Core.Api.Utility.DateTimeUtility.GetNowTime">
|
<member name="M:Milimoe.FunGame.Core.Api.Utility.DateTimeUtility.GetNowTime">
|
||||||
<summary>
|
<summary>
|
||||||
@ -863,6 +870,21 @@
|
|||||||
<param name="path">相对路径</param>
|
<param name="path">相对路径</param>
|
||||||
<returns>内容</returns>
|
<returns>内容</returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Milimoe.FunGame.Core.Api.Utility.TXTHelper.WriteTXT(System.String,System.String,System.String)">
|
||||||
|
<summary>
|
||||||
|
写入TXT文件内容(如不存在文件会创建,反之新起一行追加)
|
||||||
|
</summary>
|
||||||
|
<param name="message"></param>
|
||||||
|
<param name="filename">文件名</param>
|
||||||
|
<param name="path">相对路径</param>
|
||||||
|
<returns>内容</returns>
|
||||||
|
</member>
|
||||||
|
<member name="M:Milimoe.FunGame.Core.Api.Utility.TXTHelper.AppendErrorLog(System.String)">
|
||||||
|
<summary>
|
||||||
|
追加错误日志 默认写入logs文件夹下的当日日期.log文件
|
||||||
|
</summary>
|
||||||
|
<param name="msg"></param>
|
||||||
|
</member>
|
||||||
<member name="T:Milimoe.FunGame.Core.Api.Utility.TwoFactorAuthenticator">
|
<member name="T:Milimoe.FunGame.Core.Api.Utility.TwoFactorAuthenticator">
|
||||||
<summary>
|
<summary>
|
||||||
Aka. 2FA 双重认证 双因素身份验证
|
Aka. 2FA 双重认证 双因素身份验证
|
||||||
@ -2487,6 +2509,13 @@
|
|||||||
<param name="options"></param>
|
<param name="options"></param>
|
||||||
<returns></returns>
|
<returns></returns>
|
||||||
</member>
|
</member>
|
||||||
|
<member name="M:Milimoe.FunGame.Core.Service.JsonManager.IsCompleteJson``1(System.String)">
|
||||||
|
<summary>
|
||||||
|
检查字符串是否为完整的JSON对象
|
||||||
|
</summary>
|
||||||
|
<param name="json"></param>
|
||||||
|
<returns></returns>
|
||||||
|
</member>
|
||||||
<member name="P:Milimoe.FunGame.Core.Service.MailManager.SmtpClients">
|
<member name="P:Milimoe.FunGame.Core.Service.MailManager.SmtpClients">
|
||||||
<summary>
|
<summary>
|
||||||
用于保存Smtp客户端
|
用于保存Smtp客户端
|
||||||
|
@ -112,7 +112,5 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
|||||||
{
|
{
|
||||||
Instance?.Close();
|
Instance?.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetTypeString(SocketMessageType type) => SocketSet.GetTypeString(type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Milimoe.FunGame.Core.Interface.Base;
|
using Milimoe.FunGame.Core.Interface.Base;
|
||||||
using Milimoe.FunGame.Core.Library.Constant;
|
using Milimoe.FunGame.Core.Library.Constant;
|
||||||
|
using Milimoe.FunGame.Core.Library.Exception;
|
||||||
using Milimoe.FunGame.Core.Service;
|
using Milimoe.FunGame.Core.Service;
|
||||||
|
|
||||||
namespace Milimoe.FunGame.Core.Library.Common.Network
|
namespace Milimoe.FunGame.Core.Library.Common.Network
|
||||||
@ -66,8 +67,9 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
catch
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
|
Api.Utility.TXTHelper.AppendErrorLog(e.GetErrorInfo());
|
||||||
throw new SocketWrongInfoException();
|
throw new SocketWrongInfoException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -87,8 +89,9 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
catch
|
catch (System.Exception e)
|
||||||
{
|
{
|
||||||
|
Api.Utility.TXTHelper.AppendErrorLog(e.GetErrorInfo());
|
||||||
throw new SocketWrongInfoException();
|
throw new SocketWrongInfoException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,7 +181,5 @@ namespace Milimoe.FunGame.Core.Library.Common.Network
|
|||||||
if (_HeartBeatFaileds++ >= 3)
|
if (_HeartBeatFaileds++ >= 3)
|
||||||
throw new LostConnectException();
|
throw new LostConnectException();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetTypeString(SocketMessageType type) => SocketSet.GetTypeString(type);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,8 +223,10 @@ namespace Milimoe.FunGame.Core.Library.Constant
|
|||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
General,
|
General,
|
||||||
DateOnly,
|
LongDateOnly,
|
||||||
TimeOnly,
|
ShortDateOnly,
|
||||||
|
LongTimeOnly,
|
||||||
|
ShortTimeOnly,
|
||||||
Year4,
|
Year4,
|
||||||
Year2,
|
Year2,
|
||||||
Month,
|
Month,
|
||||||
|
@ -215,5 +215,25 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
json = "[" + json.Replace("}{", "},{") + "]"; // 将Json字符串转换为数组
|
json = "[" + json.Replace("}{", "},{") + "]"; // 将Json字符串转换为数组
|
||||||
return JsonSerializer.Deserialize<List<T>>(json, options) ?? new List<T>();
|
return JsonSerializer.Deserialize<List<T>>(json, options) ?? new List<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检查字符串是否为完整的JSON对象
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="json"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal static bool IsCompleteJson<T>(string json)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// 尝试解析JSON数据,如果成功则表示接收到完整的JSON
|
||||||
|
GetObject<T>(json);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// JSON解析失败,表示接收到的数据不完整
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
SmtpClientInfo Info = Sender.SmtpClientInfo;
|
SmtpClientInfo Info = Sender.SmtpClientInfo;
|
||||||
SmtpClient Smtp;
|
SmtpClient Smtp;
|
||||||
Guid MailSenderID = Sender.MailSenderID;
|
Guid MailSenderID = Sender.MailSenderID;
|
||||||
if (!SmtpClients.ContainsKey(MailSenderID))
|
if (!SmtpClients.TryGetValue(MailSenderID, out SmtpClient? value))
|
||||||
{
|
{
|
||||||
Smtp = new()
|
Smtp = new()
|
||||||
{
|
{
|
||||||
@ -63,7 +63,7 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
};
|
};
|
||||||
SmtpClients.Add(MailSenderID, Smtp);
|
SmtpClients.Add(MailSenderID, Smtp);
|
||||||
}
|
}
|
||||||
else Smtp = SmtpClients[MailSenderID];
|
else Smtp = value;
|
||||||
MailMessage Msg = new()
|
MailMessage Msg = new()
|
||||||
{
|
{
|
||||||
Subject = Mail.Subject,
|
Subject = Mail.Subject,
|
||||||
@ -92,6 +92,7 @@ namespace Milimoe.FunGame.Core.Service
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
ErrorMsg = e.GetErrorInfo();
|
ErrorMsg = e.GetErrorInfo();
|
||||||
|
Api.Utility.TXTHelper.AppendErrorLog(ErrorMsg);
|
||||||
return MailSendResult.Fail;
|
return MailSendResult.Fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user