EX添加日志记录
This commit is contained in:
commit
aa1b08f6c4
4 files changed
+86
-3
No files matched your search
+2
-2
@@ -5,12 +5,12 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:local="clr-namespace:formula_manage.EX"
|
xmlns:local="clr-namespace:formula_manage.EX"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="ExProgram" Height="450" Width="800">
|
Title="ExProgram" Height="450" Width="800" Background="#FFE0E0E0">
|
||||||
<Grid>
|
<Grid>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<RichTextBox Margin="0,300,0,0" IsReadOnly="True">
|
<RichTextBox x:Name="textLog" Margin="0,300,0,0" IsReadOnly="True" VerticalScrollBarVisibility="Visible" Background="White">
|
||||||
<FlowDocument>
|
<FlowDocument>
|
||||||
<Paragraph>
|
<Paragraph>
|
||||||
<Run Text="TEXTLOG"/>
|
<Run Text="TEXTLOG"/>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using formula_manage.UserClass;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@@ -22,6 +23,7 @@ namespace formula_manage.EX
|
|||||||
public ExProgram()
|
public ExProgram()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
Log.SetTextControl(textLog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Documents;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using System.Windows.Media;
|
||||||
|
|
||||||
|
namespace formula_manage.UserClass
|
||||||
|
{
|
||||||
|
public static class Log
|
||||||
|
{
|
||||||
|
private const int MaxCount = 1000;
|
||||||
|
private static int Count = 0;
|
||||||
|
private static RichTextBox textControl;
|
||||||
|
private static InlineCollection inlines;
|
||||||
|
|
||||||
|
//设置主控件
|
||||||
|
public static void SetTextControl(RichTextBox _textBox)
|
||||||
|
{
|
||||||
|
textControl = _textBox;
|
||||||
|
Paragraph graph = new Paragraph();
|
||||||
|
inlines = graph.Inlines;
|
||||||
|
textControl.Document.Blocks.Add(graph);
|
||||||
|
}
|
||||||
|
|
||||||
|
//输出黑色消息
|
||||||
|
public static void Info(string format, params object[] args)
|
||||||
|
{
|
||||||
|
AppendText(Brushes.Black, format, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
//输出绿色消息
|
||||||
|
public static void Suc(string format, params object[] args)
|
||||||
|
{
|
||||||
|
AppendText(Brushes.DarkGreen, format, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
//输出黄色消息
|
||||||
|
public static void Warning(string format, params object[] args)
|
||||||
|
{
|
||||||
|
AppendText(Brushes.DarkOrange, format, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
//输出红色消息
|
||||||
|
public static void Error(string format, params object[] args)
|
||||||
|
{
|
||||||
|
AppendText(Brushes.Red, format, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
//清除日志
|
||||||
|
public static void Clear()
|
||||||
|
{
|
||||||
|
Count = 0;
|
||||||
|
inlines.Clear();
|
||||||
|
textControl.ScrollToEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void AppendText(Brush color, string format, params object[] args)
|
||||||
|
{
|
||||||
|
textControl.BeginChange();
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.Append("[");
|
||||||
|
builder.Append(Count++);
|
||||||
|
builder.Append("] : ");
|
||||||
|
builder.Append(string.Format(format, (object[])args));
|
||||||
|
builder.Append("\n");
|
||||||
|
string str = builder.ToString();
|
||||||
|
inlines.Add(new Run(str) { Foreground = color });
|
||||||
|
if (inlines.Count > MaxCount)
|
||||||
|
{
|
||||||
|
inlines.Remove(inlines.FirstInline);
|
||||||
|
}
|
||||||
|
textControl.ScrollToEnd();
|
||||||
|
textControl.EndChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -261,6 +261,7 @@
|
|||||||
<Compile Include="UserClass\DataGridHelper.cs" />
|
<Compile Include="UserClass\DataGridHelper.cs" />
|
||||||
<Compile Include="UserClass\HardwareSN.cs" />
|
<Compile Include="UserClass\HardwareSN.cs" />
|
||||||
<Compile Include="UserClass\IniFile.cs" />
|
<Compile Include="UserClass\IniFile.cs" />
|
||||||
|
<Compile Include="UserClass\Log.cs" />
|
||||||
<Compile Include="UserClass\MD5check.cs" />
|
<Compile Include="UserClass\MD5check.cs" />
|
||||||
<Compile Include="UserClass\PressKey.cs" />
|
<Compile Include="UserClass\PressKey.cs" />
|
||||||
<Compile Include="UserClass\DataTableForToObservableCollection.cs" />
|
<Compile Include="UserClass\DataTableForToObservableCollection.cs" />
|
||||||
|
|||||||
Reference in new issue
Block a user