ECGPrint/1200Gxml心电图绘制/服务/ConsoleLogger.cs

54 lines
1.6 KiB
C#
Raw Normal View History

2024-12-25 17:24:22 +08:00
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HTTPServerLib;
namespace _1200Gxml心电图绘制
{
public class ConsoleLogger:ILogger
{
private Control _logControl; // 假设你有一个用于显示日志的Control
private const int MaxLogLength = 10000; // 设置最大日志长度
public ConsoleLogger(Control logControl)
{
_logControl = logControl;
}
public void Log(object message)
{
try
{
// 是否进行书写日志
if (ConfigurationManager.AppSettings["log"] == "1")
{
if (_logControl.InvokeRequired)
{
_logControl.Invoke(new Action<object>(Log), message);
}
else
{
// 检查日志内容是否超过最大长度
if (_logControl.Text.Length + message.ToString().Length + Environment.NewLine.Length > MaxLogLength)
{
// 清空日志控件
_logControl.Text = string.Empty;
}
// 将日志信息添加到Control中例如TextBox或RichTextBox
_logControl.Text += message + Environment.NewLine;
}
}
}
catch (Exception ex)
{
}
}
}
}