89 lines
4.0 KiB
C#
89 lines
4.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.IO;
|
|
|
|
namespace MobilePayCheck
|
|
{
|
|
public class LogHelper
|
|
{
|
|
|
|
public static string path = System.AppDomain.CurrentDomain.BaseDirectory;
|
|
public static void WriteSendLog(string LogData)
|
|
{
|
|
LogData = DateTime.Now.ToLongTimeString() + ":" + LogData;
|
|
string LogName = "日志_Send" + System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() +
|
|
"-" + System.DateTime.Now.Day.ToString() + ".log";
|
|
string filename = path + "\\" + LogName;
|
|
FileStream fs = new FileStream(filename, FileMode.OpenOrCreate);
|
|
fs.Seek(0, SeekOrigin.End);
|
|
byte[] _data = new UTF8Encoding().GetBytes(LogData + "\r\n");
|
|
fs.Write(_data, 0, _data.Length);
|
|
fs.Flush();
|
|
fs.Close();
|
|
MoveFiles("日志_Send*", "Log", -5);
|
|
}
|
|
|
|
public static void WriteReceiveLog(string LogData)
|
|
{
|
|
if (FilterContent(LogData))
|
|
{
|
|
return;
|
|
}
|
|
LogData = DateTime.Now.ToLongTimeString() + ":" + LogData;
|
|
string LogName = "日志_Receive" + System.DateTime.Now.Year.ToString() + "-" + System.DateTime.Now.Month.ToString() +
|
|
"-" + System.DateTime.Now.Day.ToString() + ".log";
|
|
string filename = path + "\\" + LogName;
|
|
FileStream fs = new FileStream(filename, FileMode.OpenOrCreate);
|
|
fs.Seek(0, SeekOrigin.End);
|
|
byte[] _data = new UTF8Encoding().GetBytes(LogData + "\r\n");
|
|
fs.Write(_data, 0, _data.Length);
|
|
fs.Flush();
|
|
fs.Close();
|
|
MoveFiles("日志_Receive*", "Log", -5);
|
|
}
|
|
|
|
public static void MoveFiles(string FileName, string FilePath = "Log", int DeleteDays = -30, string MovePath = "")
|
|
{
|
|
MovePath = MovePath == "" ? path : MovePath;
|
|
if (!Directory.Exists(MovePath + "\\" + FilePath))
|
|
{
|
|
Directory.CreateDirectory(MovePath + "\\" + FilePath);
|
|
}
|
|
DirectoryInfo _DirectoryInfo = new DirectoryInfo(MovePath);
|
|
foreach (FileInfo _FileInfo in _DirectoryInfo.GetFiles(FileName, SearchOption.TopDirectoryOnly))
|
|
{
|
|
if (_FileInfo.LastWriteTime < DateTime.Now.Date.AddDays(DeleteDays))
|
|
{
|
|
if (File.Exists(MovePath + "\\" + FilePath + "\\" + _FileInfo.Name))
|
|
{
|
|
File.Delete(MovePath + "\\" + FilePath + "\\" + _FileInfo.Name);
|
|
}
|
|
_FileInfo.MoveTo(MovePath + "\\" + FilePath + "\\" + _FileInfo.Name);
|
|
//_FileInfo.Delete();
|
|
}
|
|
}
|
|
}
|
|
|
|
public static bool FilterContent(string Content)
|
|
{
|
|
if (Content.StartsWith("远程主机强迫关闭了一个现有的连接") || Content.ToUpper().Contains("ORA-01033") ||
|
|
Content.StartsWith("由于目标计算机积极拒绝,无法连接") || Content.ToUpper().Contains("ORA-01089") ||
|
|
Content.ToUpper().Contains("ORA-02067") || Content.ToUpper().Contains("ORA-03113") ||
|
|
Content.ToUpper().Contains("ORA-03114") || Content.ToUpper().Contains("ORA-03135") ||
|
|
Content.ToUpper().Contains("ORA-12514") || Content.ToUpper().Contains("ORA-12520") ||
|
|
Content.ToUpper().Contains("ORA-12528") || Content.ToUpper().Contains("ORA-12541") ||
|
|
Content.ToUpper().Contains("ORA-12547") || Content.ToUpper().Contains("ORA-12571") ||
|
|
Content.StartsWith("由于连接方在一段时间后没有正确答复或连接的主机没有反应") ||
|
|
Content.StartsWith("在某个线程上创建的控件不能成为在另一个线程上创建的控件的父级"))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|