old_flsystem/FLSystem/Forms/system_log_control.cs

136 lines
4.7 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Api.Framework;
using Chat.Framework;
using DevExpress.XtraEditors;
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using Api.Framework.Events;
namespace FLSystem.Forms
{
public partial class system_log_control : DevExpress.XtraEditors.XtraUserControl
{
public system_log_control()
{
InitializeComponent();
EventClient.LogEvent += EventClient_LogEvent;
ChatClient.Events.WXWriteLogEvent += Events_WXWriteLogEvent;
this.Disposed += System_log_control_Disposed;
this.is_roll = ApiClient.Setting.SystemConfig.show_debug_log;
this.buttonCheck.Checked = this.is_roll;
}
private void System_log_control_Disposed(object sender, EventArgs e)
{
EventClient.LogEvent -= EventClient_LogEvent;
ChatClient.Events.WXWriteLogEvent -= Events_WXWriteLogEvent;
//tokenSource.Cancel();
}
private void Events_WXWriteLogEvent(object sender, Chat.Framework.WXSdk.Events.WXWriteLog e)
{
//if (e.Client.User != null && e.Client.User.Uin != 0) OnLog($"{e.Client.User.Nick}({e.Client.WeixinHao}){e.Message}");
//else OnLog(e.Message);
if (e.Client.User != null && e.Client.User.Uin != 0) showLog($"{e.Client.User.Nick}({e.Client.WeixinHao}){e.Message}");
else showLog(e.Message);
}
public void showLog(string log)
{
this.SafeInvoke(() =>
{
OnLog(log);
});
}
private bool is_roll = true;
private void EventClient_LogEvent(object sender, Api.Framework.Events.LogEvents e)
{
//OnLog(e.Message);
//this.BeginInvoke(updateLog, e.Message);
try
{
showLog(e.Message);
}
catch (Exception ex)
{ }
}
private static object lock_log = new object();
private void OnLog(string message)
{
try
{
var _msg = message;
try
{
string name = Api.Framework.Tools.Util.MapFile(DateTime.Now.ToString("yyyy-MM-dd") + ".log", "Cache\\系统日志");
File.AppendAllLines(name, new string[] { DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "-->" + _msg });
}
catch
{ }
if (is_roll)
{
try
{
if (this.richTextBox1.Lines.Length > 1000)
this.richTextBox1.Text = "";
if (!string.IsNullOrEmpty(this.richTextBox1.Text))
this.richTextBox1.AppendText("\r\n");
this.richTextBox1.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "-->" + message);
this.richTextBox1.SelectionStart = this.richTextBox1.Text.Length;
this.richTextBox1.ScrollToCaret();
}
catch (Exception ex)
{ }
#region xxx
//this.Invoke(new Action(delegate
//{
//try
//{
// if (this.log_text.Lines.Length > 1000)
// this.log_text.Text = "";
// if (!string.IsNullOrEmpty(this.log_text.Text))
// this.log_text.Text += "\r\n";
// this.log_text.Text += DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "-->" + message;
// this.log_text.SelectionStart = this.log_text.Text.Length;
// this.log_text.ScrollToCaret();
//}
//catch (Exception)
//{ }
//}));
#endregion
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void buttonCheck1_Click(object sender, EventArgs e)
{
try
{
this.is_roll = this.buttonCheck.Checked;
ApiClient.Setting.SystemConfig.show_debug_log = this.is_roll;
}
catch (Exception)
{ }
}
private void hyperlinkLabelControl1_Click(object sender, EventArgs e)
{
//this.log_text.Text = "";
this.richTextBox1.Text = "";
}
}
}