You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.2 KiB
73 lines
2.2 KiB
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Shentun.Peis.PlugIns.Extensions
|
|
{
|
|
public class PluginLogger
|
|
{
|
|
|
|
private string _logFilePath;
|
|
private string _logFilePath2;
|
|
|
|
public PluginLogger()
|
|
{
|
|
var logDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "PlugLogs");
|
|
if (!Directory.Exists(logDir))
|
|
Directory.CreateDirectory(logDir);
|
|
_logFilePath = Path.Combine(logDir, $"plugin_{DateTime.Now:yyyyMMdd}.log");
|
|
|
|
|
|
_logFilePath2 = Path.Combine(logDir, $"plugin_result_{DateTime.Now:yyyyMMdd}.log");
|
|
}
|
|
|
|
|
|
|
|
// 写日志方法
|
|
public void Log(string logT, string message)
|
|
{
|
|
try
|
|
{
|
|
var logEntry = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} [{logT}] {message}";
|
|
File.AppendAllText(_logFilePath, logEntry + Environment.NewLine);
|
|
}
|
|
catch { /* 忽略日志错误 */ }
|
|
}
|
|
|
|
public void Log(string logT, Exception ex, string message)
|
|
{
|
|
try
|
|
{
|
|
var logEntry = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} [{logT}] {message}\n{ex}";
|
|
File.AppendAllText(_logFilePath, logEntry + Environment.NewLine);
|
|
}
|
|
catch { /* 忽略日志错误 */ }
|
|
}
|
|
|
|
// 写日志方法
|
|
public void LogResult(string logT, string message)
|
|
{
|
|
try
|
|
{
|
|
var logEntry = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} [{logT}] {message}";
|
|
File.AppendAllText(_logFilePath2, logEntry + Environment.NewLine);
|
|
}
|
|
catch { /* 忽略日志错误 */ }
|
|
}
|
|
|
|
// 写日志方法
|
|
public void LogResult(string logT, Exception ex, string message)
|
|
{
|
|
try
|
|
{
|
|
var logEntry = $"{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff} [{logT}] {message}\n{ex}";
|
|
File.AppendAllText(_logFilePath2, logEntry + Environment.NewLine);
|
|
}
|
|
catch { /* 忽略日志错误 */ }
|
|
}
|
|
}
|
|
}
|