日志方法替换

This commit is contained in:
Colin 2023-08-16 22:06:12 +08:00
parent ef29d2565b
commit 972890b7c5
3 changed files with 46 additions and 34 deletions

View File

@ -151,7 +151,7 @@
</PackageReference>
<PackageReference Include="Costura.Fody">
<Version>5.7.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive; compile</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Serilog.Sinks.File">

View File

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<AtuoUpdate>
<ConnectionString>Data Source=100.101.220.106;Initial Catalog=AIMSDB_ETKQQMYYY;User ID=sa;Password=Sm@123456;</ConnectionString>
<DataConnectionString>Data Source=100.101.220.106;Initial Catalog=AIMSDB_DATA;User ID=sa;Password=Sm@123456;</DataConnectionString>
<!--<ConnectionString>Data Source=.;Initial Catalog=AIMSDB_FJZPTFYY;User ID=sa;Password=Test2020;</ConnectionString>
<DataConnectionString>Data Source=.;Initial Catalog=AIMSDB_DATA;User ID=sa;Password=Test2020;</DataConnectionString>-->
<!--<ConnectionString>Data Source=bj;Initial Catalog=AIMSDB_ETKQQMYYY;User ID=sa;Password=Sm@123456;</ConnectionString>
<DataConnectionString>Data Source=bj;Initial Catalog=AIMSDB_DATA;User ID=sa;Password=Sm@123456;</DataConnectionString>-->
<ConnectionString>Data Source=bj;Initial Catalog=AIMSDB_FJZPTFYY;User ID=sa;Password=Test2020;</ConnectionString>
<DataConnectionString>Data Source=bj;Initial Catalog=AIMSDB_DATA;User ID=sa;Password=Test2020;</DataConnectionString>
<HisConnectionStringOracel>Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.10.7)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=orcl2))));Persist Security Info=True;User ID=smview;Password=i39;</HisConnectionStringOracel>
<LastLoginNo></LastLoginNo>
<LastOperationSite></LastOperationSite>

View File

@ -1,4 +1,6 @@
using HelperDB;
using CCIS.Shared;
using HelperDB;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Data;
@ -11,6 +13,7 @@ using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using static Mono.Security.X509.X520;
namespace AIMSExtension
{
@ -524,35 +527,44 @@ namespace AIMSExtension
/// </summary>
/// <param name="ex">异常</param>
/// <param name="LogAddress">日志文件地址</param>
public static void WriteLog(Exception ex, string LogAddress = "")
[Obsolete]
public static void WriteLog(Exception ex, string LogAddress = "",
[System.Runtime.CompilerServices.CallerMemberName] string memberName = "",
[System.Runtime.CompilerServices.CallerFilePath] string sourceFilePath = "",
[System.Runtime.CompilerServices.CallerLineNumber] int sourceLineNumber = 0)
{
try
{
if (!Directory.Exists(Environment.CurrentDirectory + "/Log"))
{
Directory.CreateDirectory(Environment.CurrentDirectory + "/Log");
}
//如果日志文件为空则默认在Debug目internal录下新建 YYYY-mm-dd_Log.log文件
if (LogAddress == "")
{
LogAddress = Environment.CurrentDirectory + "\\Log\\" +
DateTime.Now.Year + '-' +
DateTime.Now.Month + '-' +
DateTime.Now.Day + "_Log.log";
}
//把异常信息输出到文件
StreamWriter sw = new StreamWriter(LogAddress, true);
sw.WriteLine("当前时间:" + DateTime.Now.ToString());
sw.WriteLine("异常信息:" + ex.Message);
sw.WriteLine("异常对象:" + ex.Source);
sw.WriteLine("调用堆栈:\n" + ex.StackTrace);
sw.WriteLine("触发方法:" + ex.TargetSite);
sw.WriteLine();
sw.Close();
}
catch (Exception)
{
}
var log = SharedContext.StaticInstance.LoggerFactory.CreateLogger("OldLog");
log.LogError(ex, "异常信息:{Message},触发异常方法:{memberName},异常行号:{sourceLineNumber},异常文件:{sourceFilePath}",
ex.Message,memberName, sourceLineNumber, sourceFilePath);
return;
//try
//{
// if (!Directory.Exists(Environment.CurrentDirectory + "/Log"))
// {
// Directory.CreateDirectory(Environment.CurrentDirectory + "/Log");
// }
// //如果日志文件为空则默认在Debug目internal录下新建 YYYY-mm-dd_Log.log文件
// if (LogAddress == "")
// {
// LogAddress = Environment.CurrentDirectory + "\\Log\\" +
// DateTime.Now.Year + '-' +
// DateTime.Now.Month + '-' +
// DateTime.Now.Day + "_Log.log";
// }
// //把异常信息输出到文件
// StreamWriter sw = new StreamWriter(LogAddress, true);
// sw.WriteLine("当前时间:" + DateTime.Now.ToString());
// sw.WriteLine("异常信息:" + ex.Message);
// sw.WriteLine("异常对象:" + ex.Source);
// sw.WriteLine("调用堆栈:\n" + ex.StackTrace);
// sw.WriteLine("触发方法:" + ex.TargetSite);
// sw.WriteLine();
// sw.Close();
//}
//catch (Exception)
//{
//}
}