修复LOG提交异常

This commit is contained in:
liu.wenjie
2021-12-18 13:20:47 +08:00
parent f72cca2331
commit a4db2f0ff2
10 changed files with 2557 additions and 0 deletions

141
ToolLib.Log/Logger/LogDetail.Designer.cs generated Normal file
View File

@@ -0,0 +1,141 @@
namespace Logger
{
partial class LogDetail
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LogDetail));
this.panel1 = new System.Windows.Forms.Panel();
this.richDetail = new System.Windows.Forms.RichTextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.txbLogTime = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.txbLogLevel = new System.Windows.Forms.TextBox();
this.panel1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.White;
this.panel1.Controls.Add(this.richDetail);
this.panel1.Controls.Add(this.label3);
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.txbLogTime);
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.txbLogLevel);
this.panel1.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(743, 275);
this.panel1.TabIndex = 0;
//
// richDetail
//
this.richDetail.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.richDetail.Location = new System.Drawing.Point(127, 102);
this.richDetail.Name = "richDetail";
this.richDetail.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedVertical;
this.richDetail.Size = new System.Drawing.Size(604, 161);
this.richDetail.TabIndex = 2;
this.richDetail.Text = "";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(37, 165);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(76, 20);
this.label3.TabIndex = 1;
this.label3.Text = "Log详细";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(37, 61);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(76, 20);
this.label2.TabIndex = 1;
this.label2.Text = "Log时间";
//
// txbLogTime
//
this.txbLogTime.Location = new System.Drawing.Point(127, 58);
this.txbLogTime.Name = "txbLogTime";
this.txbLogTime.Size = new System.Drawing.Size(192, 26);
this.txbLogTime.TabIndex = 0;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(37, 21);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(76, 20);
this.label1.TabIndex = 1;
this.label1.Text = "Log级别";
//
// txbLogLevel
//
this.txbLogLevel.Location = new System.Drawing.Point(127, 18);
this.txbLogLevel.Name = "txbLogLevel";
this.txbLogLevel.Size = new System.Drawing.Size(192, 26);
this.txbLogLevel.TabIndex = 0;
//
// LogDetail
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(743, 275);
this.Controls.Add(this.panel1);
this.Font = new System.Drawing.Font("微软雅黑", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
this.MaximizeBox = false;
this.Name = "LogDetail";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Log详细信息";
this.Load += new System.EventHandler(this.LogDetail_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.TextBox txbLogLevel;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.RichTextBox richDetail;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox txbLogTime;
private System.Windows.Forms.Label label3;
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Logger
{
public partial class LogDetail : Form
{
string logMsg = string.Empty;
public LogDetail(string inputMsg)
{
InitializeComponent();
logMsg = inputMsg;
}
private void LogDetail_Load(object sender, EventArgs e)
{
try
{
string time = Regex.Split(logMsg, " -> ")[0];
string msgLevel = Regex.Split(logMsg, " -> ")[1].Split(',')[0];
string msgDetal = Regex.Split(logMsg, " -> ")[1];
txbLogTime.Text = time;
txbLogLevel.Text = msgLevel;
txbLogLevel.BackColor = (msgLevel == "Warn" || msgLevel == "Exception") ? Color.Red : Color.Lime;
richDetail.Text = msgDetal;
}
catch (Exception)
{
richDetail.Text = logMsg;
}
}
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

Binary file not shown.

275
ToolLib.Log/Logger/UserLogger.Designer.cs generated Normal file
View File

@@ -0,0 +1,275 @@
namespace Logger
{
partial class UserLogger
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(UserLogger));
this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components);
this.btnClear = new System.Windows.Forms.ToolStripMenuItem();
this.listBoxAll = new System.Windows.Forms.ListBox();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.pageAll = new System.Windows.Forms.TabPage();
this.pageInfo = new System.Windows.Forms.TabPage();
this.listBoxInfo = new System.Windows.Forms.ListBox();
this.pageWarn = new System.Windows.Forms.TabPage();
this.listBoxWarn = new System.Windows.Forms.ListBox();
this.padeDebug = new System.Windows.Forms.TabPage();
this.listBoxDebug = new System.Windows.Forms.ListBox();
this.pageExpection = new System.Windows.Forms.TabPage();
this.listBoxExpection = new System.Windows.Forms.ListBox();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
this.contextMenuStrip1.SuspendLayout();
this.tabControl1.SuspendLayout();
this.pageAll.SuspendLayout();
this.pageInfo.SuspendLayout();
this.pageWarn.SuspendLayout();
this.padeDebug.SuspendLayout();
this.pageExpection.SuspendLayout();
this.SuspendLayout();
//
// contextMenuStrip1
//
this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.btnClear});
this.contextMenuStrip1.Name = "contextMenuStrip1";
this.contextMenuStrip1.Size = new System.Drawing.Size(101, 26);
//
// btnClear
//
this.btnClear.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.btnClear.Name = "btnClear";
this.btnClear.Size = new System.Drawing.Size(100, 22);
this.btnClear.Text = "清空";
this.btnClear.Click += new System.EventHandler(this.btnClear_Click);
//
// listBoxAll
//
this.listBoxAll.BackColor = System.Drawing.SystemColors.Info;
this.listBoxAll.ContextMenuStrip = this.contextMenuStrip1;
this.listBoxAll.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBoxAll.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.listBoxAll.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.listBoxAll.FormattingEnabled = true;
this.listBoxAll.ItemHeight = 18;
this.listBoxAll.Location = new System.Drawing.Point(3, 3);
this.listBoxAll.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.listBoxAll.Name = "listBoxAll";
this.listBoxAll.Size = new System.Drawing.Size(662, 313);
this.listBoxAll.TabIndex = 0;
this.listBoxAll.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_DrawItem);
this.listBoxAll.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick);
//
// tabControl1
//
this.tabControl1.Alignment = System.Windows.Forms.TabAlignment.Bottom;
this.tabControl1.Controls.Add(this.pageAll);
this.tabControl1.Controls.Add(this.pageInfo);
this.tabControl1.Controls.Add(this.pageWarn);
this.tabControl1.Controls.Add(this.padeDebug);
this.tabControl1.Controls.Add(this.pageExpection);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.ImageList = this.imageList1;
this.tabControl1.Location = new System.Drawing.Point(0, 0);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(676, 347);
this.tabControl1.TabIndex = 1;
//
// pageAll
//
this.pageAll.Controls.Add(this.listBoxAll);
this.pageAll.ImageIndex = 3;
this.pageAll.Location = new System.Drawing.Point(4, 4);
this.pageAll.Name = "pageAll";
this.pageAll.Padding = new System.Windows.Forms.Padding(3);
this.pageAll.Size = new System.Drawing.Size(668, 319);
this.pageAll.TabIndex = 0;
this.pageAll.Text = "全部";
this.pageAll.UseVisualStyleBackColor = true;
//
// pageInfo
//
this.pageInfo.Controls.Add(this.listBoxInfo);
this.pageInfo.ImageIndex = 2;
this.pageInfo.Location = new System.Drawing.Point(4, 4);
this.pageInfo.Name = "pageInfo";
this.pageInfo.Padding = new System.Windows.Forms.Padding(3);
this.pageInfo.Size = new System.Drawing.Size(668, 319);
this.pageInfo.TabIndex = 1;
this.pageInfo.Text = "消息";
this.pageInfo.UseVisualStyleBackColor = true;
//
// listBoxInfo
//
this.listBoxInfo.BackColor = System.Drawing.SystemColors.Info;
this.listBoxInfo.ContextMenuStrip = this.contextMenuStrip1;
this.listBoxInfo.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBoxInfo.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.listBoxInfo.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.listBoxInfo.FormattingEnabled = true;
this.listBoxInfo.ItemHeight = 18;
this.listBoxInfo.Location = new System.Drawing.Point(3, 3);
this.listBoxInfo.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.listBoxInfo.Name = "listBoxInfo";
this.listBoxInfo.Size = new System.Drawing.Size(662, 313);
this.listBoxInfo.TabIndex = 1;
this.listBoxInfo.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_DrawItem);
this.listBoxInfo.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick);
//
// pageWarn
//
this.pageWarn.Controls.Add(this.listBoxWarn);
this.pageWarn.ImageIndex = 4;
this.pageWarn.Location = new System.Drawing.Point(4, 4);
this.pageWarn.Name = "pageWarn";
this.pageWarn.Size = new System.Drawing.Size(668, 319);
this.pageWarn.TabIndex = 2;
this.pageWarn.Text = "警告";
this.pageWarn.UseVisualStyleBackColor = true;
//
// listBoxWarn
//
this.listBoxWarn.BackColor = System.Drawing.SystemColors.Info;
this.listBoxWarn.ContextMenuStrip = this.contextMenuStrip1;
this.listBoxWarn.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBoxWarn.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.listBoxWarn.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.listBoxWarn.FormattingEnabled = true;
this.listBoxWarn.ItemHeight = 18;
this.listBoxWarn.Location = new System.Drawing.Point(0, 0);
this.listBoxWarn.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.listBoxWarn.Name = "listBoxWarn";
this.listBoxWarn.Size = new System.Drawing.Size(668, 319);
this.listBoxWarn.TabIndex = 1;
this.listBoxWarn.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_DrawItem);
this.listBoxWarn.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick);
//
// padeDebug
//
this.padeDebug.Controls.Add(this.listBoxDebug);
this.padeDebug.ImageIndex = 0;
this.padeDebug.Location = new System.Drawing.Point(4, 4);
this.padeDebug.Name = "padeDebug";
this.padeDebug.Size = new System.Drawing.Size(668, 319);
this.padeDebug.TabIndex = 3;
this.padeDebug.Text = "调试";
this.padeDebug.UseVisualStyleBackColor = true;
//
// listBoxDebug
//
this.listBoxDebug.BackColor = System.Drawing.SystemColors.Info;
this.listBoxDebug.ContextMenuStrip = this.contextMenuStrip1;
this.listBoxDebug.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBoxDebug.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.listBoxDebug.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.listBoxDebug.FormattingEnabled = true;
this.listBoxDebug.ItemHeight = 18;
this.listBoxDebug.Location = new System.Drawing.Point(0, 0);
this.listBoxDebug.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.listBoxDebug.Name = "listBoxDebug";
this.listBoxDebug.Size = new System.Drawing.Size(668, 319);
this.listBoxDebug.TabIndex = 1;
this.listBoxDebug.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_DrawItem);
this.listBoxDebug.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick);
//
// pageExpection
//
this.pageExpection.Controls.Add(this.listBoxExpection);
this.pageExpection.ImageIndex = 1;
this.pageExpection.Location = new System.Drawing.Point(4, 4);
this.pageExpection.Name = "pageExpection";
this.pageExpection.Size = new System.Drawing.Size(668, 319);
this.pageExpection.TabIndex = 4;
this.pageExpection.Text = "异常";
this.pageExpection.UseVisualStyleBackColor = true;
//
// listBoxExpection
//
this.listBoxExpection.BackColor = System.Drawing.SystemColors.Info;
this.listBoxExpection.ContextMenuStrip = this.contextMenuStrip1;
this.listBoxExpection.Dock = System.Windows.Forms.DockStyle.Fill;
this.listBoxExpection.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
this.listBoxExpection.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.listBoxExpection.FormattingEnabled = true;
this.listBoxExpection.ItemHeight = 18;
this.listBoxExpection.Location = new System.Drawing.Point(0, 0);
this.listBoxExpection.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.listBoxExpection.Name = "listBoxExpection";
this.listBoxExpection.Size = new System.Drawing.Size(668, 319);
this.listBoxExpection.TabIndex = 2;
this.listBoxExpection.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_DrawItem);
this.listBoxExpection.DoubleClick += new System.EventHandler(this.listBox1_DoubleClick);
//
// imageList1
//
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
this.imageList1.Images.SetKeyName(0, "debug.ico");
this.imageList1.Images.SetKeyName(1, "error.ico");
this.imageList1.Images.SetKeyName(2, "info.ico");
this.imageList1.Images.SetKeyName(3, "loh.ico");
this.imageList1.Images.SetKeyName(4, "warn.ico");
//
// UserLogger
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.tabControl1);
this.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Name = "UserLogger";
this.Size = new System.Drawing.Size(676, 347);
this.Load += new System.EventHandler(this.UserLogger_Load);
this.contextMenuStrip1.ResumeLayout(false);
this.tabControl1.ResumeLayout(false);
this.pageAll.ResumeLayout(false);
this.pageInfo.ResumeLayout(false);
this.pageWarn.ResumeLayout(false);
this.padeDebug.ResumeLayout(false);
this.pageExpection.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ContextMenuStrip contextMenuStrip1;
private System.Windows.Forms.ToolStripMenuItem btnClear;
public System.Windows.Forms.ListBox listBoxAll;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage pageAll;
private System.Windows.Forms.TabPage pageInfo;
public System.Windows.Forms.ListBox listBoxInfo;
private System.Windows.Forms.TabPage pageWarn;
public System.Windows.Forms.ListBox listBoxWarn;
private System.Windows.Forms.TabPage padeDebug;
public System.Windows.Forms.ListBox listBoxDebug;
private System.Windows.Forms.TabPage pageExpection;
public System.Windows.Forms.ListBox listBoxExpection;
private System.Windows.Forms.ImageList imageList1;
}
}

View File

@@ -0,0 +1,263 @@
using System;
using System.Drawing;
using System.Windows.Forms;
using Logger;
using System.Threading.Tasks;
using System.IO;
using System.Collections.Generic;
namespace Logger
{
public partial class UserLogger : UserControl
{
bool logFocus = true;
string logDictory = @"C:\MyCCDSystem\Log\";
public UserLogger()
{
InitializeComponent();
}
~UserLogger()
{
logFocus = false;
}
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
ListBox seelctBox = sender as ListBox;
if (e.Index < 0)
{ return; }
else
{
e.DrawBackground();
Brush mybsh = Brushes.Black;
// 判断是什么类型的标签,在调用时必须信息前边标注信息的类别分为InfoWarningError
try
{
MsgLevel msgLevel = (MsgLevel)Enum.Parse(typeof(MsgLevel), seelctBox.Items[e.Index].ToString().Split('>')[1].Trim().Split(',')[0]);
switch (msgLevel)
{
case MsgLevel.Info:
mybsh = Brushes.Black;
break;
case MsgLevel.Debug:
mybsh = Brushes.Green;
break;
case MsgLevel.Warn:
mybsh = Brushes.Purple;
break;
case MsgLevel.Exception:
case MsgLevel.Fatal:
mybsh = Brushes.Red;
break;
default:
mybsh = Brushes.Black;
break;
}
}
catch (Exception)
{
mybsh = Brushes.Green;
}
e.DrawFocusRectangle();
e.Graphics.DrawString(seelctBox.Items[e.Index].ToString(), e.Font, mybsh, e.Bounds, StringFormat.GenericDefault);
}
}
public void AddLog(MsgLevel msgLog, string logInfo)
{
try
{
WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss-fff") + " -> " + msgLog.ToString() + "," + logInfo);
this.Invoke((MethodInvoker)delegate
{
switch (msgLog)
{
case MsgLevel.Debug:
ControlListBox(msgLog, logInfo, listBoxDebug);
break;
case MsgLevel.Info:
ControlListBox(msgLog, logInfo, listBoxInfo);
break;
case MsgLevel.Warn:
ControlListBox(msgLog, logInfo, listBoxWarn);
break;
case MsgLevel.Exception:
case MsgLevel.Fatal:
ControlListBox(msgLog, logInfo, listBoxExpection);
break;
default:
break;
}
listBoxAll.Items.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss-fff") + " -> " + msgLog.ToString() + "," + logInfo);
listBoxAll.SelectedIndex = listBoxAll.Items.Count - 1;
if (listBoxAll.Items.Count > 1000)
{
listBoxAll.Items.Clear();
}
Application.DoEvents();
});
}
catch(Exception)
{
}
}
private void ControlListBox(MsgLevel msgLog, string logInfo,ListBox myListBox)
{
myListBox.Items.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss-fff") + " -> " + msgLog.ToString() + "," + logInfo);
myListBox.SelectedIndex = myListBox.Items.Count - 1;
if (myListBox.Items.Count > 1000)
{
myListBox.Items.Clear();
}
}
public void AddLog(MsgLevel msgLog, string logInfo, Exception ex)
{
try
{
WriteLog(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " -> " + msgLog.ToString() + "," + logInfo + ex);
this.Invoke((MethodInvoker)delegate
{
switch (msgLog)
{
case MsgLevel.Debug:
ControlListBox(msgLog, logInfo, listBoxDebug);
break;
case MsgLevel.Info:
ControlListBox(msgLog, logInfo, listBoxInfo);
break;
case MsgLevel.Warn:
ControlListBox(msgLog, logInfo, listBoxWarn);
break;
case MsgLevel.Exception:
case MsgLevel.Fatal:
ControlListBox(msgLog, logInfo, listBoxExpection);
break;
default:
break;
}
listBoxAll.Items.Add(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " -> " + msgLog.ToString() + "," + logInfo + ex);
listBoxAll.SelectedIndex = listBoxAll.Items.Count - 1;
if(listBoxAll.Items.Count >1000)
{
listBoxAll.Items.Clear();
}
Application.DoEvents();
});
}
catch (Exception)
{
}
}
public void WriteLog(string msg)
{
string time = DateTime.Now.ToString("HH:mm:ss.fff");
if (!Directory.Exists(logDictory))
{
Directory.CreateDirectory(logDictory);
}
string runningLogFileName = logDictory + DateTime.Now.ToString("yyyyMMdd") + ".log";
StreamWriter mySW = new StreamWriter(runningLogFileName, true);
mySW.WriteLine(msg);
mySW.Close();
}
object myObject = new object();
private void UserLogger_Load(object sender, EventArgs e)
{
Task startLogFocus = new Task(() =>
{
while (logFocus)
{
if (LoggerClass.logQueue.Count > 0)
{
lock(myObject)
{
LogInfo log = LoggerClass.logQueue.Dequeue();
if (log.ex != null)
{
AddLog(log.logLevel, log.message, log.ex);
}
else
{
AddLog(log.logLevel, log.message);
}
}
}
}
});
startLogFocus.Start();
}
private void btnClear_Click(object sender, EventArgs e)
{
try
{
switch (tabControl1.SelectedIndex)
{
case 0:
listBoxAll.Items.Clear();
break;
case 1:
listBoxInfo.Items.Clear();
break;
case 2:
listBoxDebug.Items.Clear();
break;
case 3:
listBoxWarn.Items.Clear();
break;
case 4:
listBoxExpection.Items.Clear();
break;
default:
break;
}
}
catch
{
}
}
private void listBox1_DoubleClick(object sender, EventArgs e)
{
ListBox mySelectBox = sender as ListBox;
if (mySelectBox.SelectedItem != null)
{
string selectInfo = mySelectBox.SelectedItem.ToString();
LogDetail myLogDetail = new LogDetail(selectInfo);
myLogDetail.Show();
}
}
}
public enum MsgLevel
{
/// <summary>
/// 0.调试信息输出
/// </summary>
Debug = 0,
/// <summary>
/// 1.业务信息记录
/// </summary>
Info = 1,
/// <summary>
/// 2.警告提醒(捕获的业务异常)
/// </summary>
Warn = 2,
/// <summary>
/// 3.发生了异常(捕获的系统异常)
/// </summary>
Exception = 3,
/// <summary>
/// 4.发生致命异常(未被捕获的异常|捕获的业务逻辑异常)
/// </summary>
Fatal = 4
}
}

View File

@@ -0,0 +1,182 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="contextMenuStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="imageList1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>182, 17</value>
</metadata>
<data name="imageList1.ImageStream" mimetype="application/x-microsoft.net.object.binary.base64">
<value>
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABA
CwAAAk1TRnQBSQFMAgEBBQEAARgBAAEYAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAASADAAEBA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