Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
Ftt_Common
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Ftt_Common
Commits
094093a6
Commit
094093a6
authored
Oct 13, 2021
by
tr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、日志查看:增加编码选择(默认(GB2312)、UTF-8、ASCII)
parent
121a941d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
87 additions
and
33 deletions
+87
-33
Tools.exe.config
AppHome/Tools.exe.config
+1
-1
wLogViewer.Designer.cs
Tools/UI/wLogViewer.Designer.cs
+26
-0
wLogViewer.cs
Tools/UI/wLogViewer.cs
+60
-32
No files found.
AppHome/Tools.exe.config
View file @
094093a6
...
...
@@ -3,7 +3,7 @@
<
appSettings
>
<
add
key
=
"LoginInfo"
value
=
"wwF/xpBzWek="
/>
<
add
key
=
"LoginVerify"
value
=
"v86f5Q3Xa7U="
/>
<
add
key
=
"UpdateTime"
value
=
"2021-10-1
1 18:11:12.770
"
/>
<
add
key
=
"UpdateTime"
value
=
"2021-10-1
2 13:45:01.513
"
/>
</
appSettings
>
<
startup
>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.8"
/>
...
...
Tools/UI/wLogViewer.Designer.cs
View file @
094093a6
...
...
@@ -36,6 +36,9 @@
this
.
textBox1
=
new
System
.
Windows
.
Forms
.
TextBox
();
this
.
splitContainer1
=
new
System
.
Windows
.
Forms
.
SplitContainer
();
this
.
progressBar1
=
new
System
.
Windows
.
Forms
.
ProgressBar
();
this
.
toolStripLabel2
=
new
System
.
Windows
.
Forms
.
ToolStripLabel
();
this
.
tscbEncoding
=
new
System
.
Windows
.
Forms
.
ToolStripComboBox
();
this
.
toolStripSeparator1
=
new
System
.
Windows
.
Forms
.
ToolStripSeparator
();
this
.
toolStrip1
.
SuspendLayout
();
((
System
.
ComponentModel
.
ISupportInitialize
)(
this
.
splitContainer1
)).
BeginInit
();
this
.
splitContainer1
.
Panel1
.
SuspendLayout
();
...
...
@@ -46,6 +49,9 @@
// toolStrip1
//
this
.
toolStrip1
.
Items
.
AddRange
(
new
System
.
Windows
.
Forms
.
ToolStripItem
[]
{
this
.
toolStripLabel2
,
this
.
tscbEncoding
,
this
.
toolStripSeparator1
,
this
.
toolStripLabel1
,
this
.
tstbLogPath
,
this
.
tsbSelectPath
});
...
...
@@ -123,6 +129,23 @@
this
.
progressBar1
.
Size
=
new
System
.
Drawing
.
Size
(
535
,
2
);
this
.
progressBar1
.
TabIndex
=
3
;
//
// toolStripLabel2
//
this
.
toolStripLabel2
.
Name
=
"toolStripLabel2"
;
this
.
toolStripLabel2
.
Size
=
new
System
.
Drawing
.
Size
(
44
,
22
);
this
.
toolStripLabel2
.
Text
=
"编码:"
;
//
// tscbEncoding
//
this
.
tscbEncoding
.
DropDownStyle
=
System
.
Windows
.
Forms
.
ComboBoxStyle
.
DropDownList
;
this
.
tscbEncoding
.
Name
=
"tscbEncoding"
;
this
.
tscbEncoding
.
Size
=
new
System
.
Drawing
.
Size
(
75
,
25
);
//
// toolStripSeparator1
//
this
.
toolStripSeparator1
.
Name
=
"toolStripSeparator1"
;
this
.
toolStripSeparator1
.
Size
=
new
System
.
Drawing
.
Size
(
6
,
25
);
//
// wLogViewer
//
this
.
AutoScaleDimensions
=
new
System
.
Drawing
.
SizeF
(
6F
,
12F
);
...
...
@@ -156,5 +179,8 @@
private
System
.
Windows
.
Forms
.
TextBox
textBox1
;
private
System
.
Windows
.
Forms
.
SplitContainer
splitContainer1
;
private
System
.
Windows
.
Forms
.
ProgressBar
progressBar1
;
private
System
.
Windows
.
Forms
.
ToolStripLabel
toolStripLabel2
;
private
System
.
Windows
.
Forms
.
ToolStripComboBox
tscbEncoding
;
private
System
.
Windows
.
Forms
.
ToolStripSeparator
toolStripSeparator1
;
}
}
\ No newline at end of file
Tools/UI/wLogViewer.cs
View file @
094093a6
...
...
@@ -28,15 +28,25 @@ namespace Tools.UI
//窗体:加载
private
void
wLogViewer_Load
(
object
sender
,
EventArgs
e
)
{
var
list
=
new
List
<
string
>
{
Encoding
.
Default
.
HeaderName
.
ToUpper
(),
Encoding
.
UTF8
.
HeaderName
.
ToUpper
(),
Encoding
.
ASCII
.
HeaderName
.
ToUpper
(),
};
this
.
tscbEncoding
.
Items
.
AddRange
(
list
.
Distinct
().
ToArray
());
this
.
tscbEncoding
.
SelectedIndex
=
0
;
}
//窗体:显示完成
private
void
wLogViewer_Shown
(
object
sender
,
EventArgs
e
)
{
this
.
tsbSelectPath
.
Click
+=
TsbSelectPath_Click
;
this
.
tstbLogPath
.
TextChanged
+=
TstbLogPath_TextChanged
;
this
.
tscbEncoding
.
SelectedIndexChanged
+=
TscbEncoding_SelectedIndexChanged
;
this
.
listBox1
.
SelectedIndexChanged
+=
ListBox1_SelectedIndexChanged
;
}
/// <summary>
/// 选择路径
/// </summary>
...
...
@@ -56,15 +66,59 @@ namespace Tools.UI
this
.
InitListBox
();
}
Task
_task
=
null
;
CancellationTokenSource
_tokenSource
=
new
CancellationTokenSource
();
/// <summary>
/// 编码切换:重新解析日志文件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private
void
TscbEncoding_SelectedIndexChanged
(
object
sender
,
EventArgs
e
)
{
this
.
OpenLogFile
();
}
/// <summary>
/// 列表切换:加载选中日志文件
/// </summary>
private
void
ListBox1_SelectedIndexChanged
(
object
sender
,
EventArgs
e
)
{
this
.
OpenLogFile
();
}
/// <summary>
/// 日志文件类型(兼容原有的txt日志和log4net日志)
/// </summary>
List
<
string
>
LogExtensions
=
new
List
<
string
>
{
".txt"
,
".log"
};
/// <summary>
/// 初始化列表框
/// </summary>
private
void
InitListBox
()
{
//清空原有项
this
.
textBox1
.
Text
=
string
.
Empty
;
this
.
listBox1
.
Items
.
Clear
();
//重新加载
if
(
Directory
.
Exists
(
this
.
LogPath
))
{
var
dirInfo
=
new
DirectoryInfo
(
this
.
LogPath
);
var
files
=
dirInfo
.
GetFiles
().
Where
(
f
=>
this
.
LogExtensions
.
Contains
(
f
.
Extension
.
ToLower
())).
Select
(
f
=>
f
.
Name
);
this
.
listBox1
.
Items
.
AddRange
(
files
.
ToArray
());
}
else
{
Utils
.
Tip
(
"路径不存在,请检查!"
);
}
}
Task
_task
=
null
;
//当前任务
CancellationTokenSource
_tokenSource
=
new
CancellationTokenSource
();
//取消令牌
/// <summary>
/// 打开日志文件
/// </summary>
private
void
OpenLogFile
()
{
var
fileName
=
this
.
listBox1
.
SelectedItem
.
ToString
();
var
isDefault
=
fileName
.
ToLower
().
EndsWith
(
".log"
);
var
encode
=
Encoding
.
Default
;
if
(!
string
.
IsNullOrEmpty
(
this
.
tscbEncoding
.
Text
))
encode
=
Encoding
.
GetEncoding
(
this
.
tscbEncoding
.
Text
);
//清空信息
this
.
textBox1
.
Text
=
string
.
Empty
;
//如果上一个任务还未结束,则取消
...
...
@@ -81,8 +135,8 @@ namespace Tools.UI
//读取日志内容
var
buffer
=
new
byte
[
1024
];
var
fs
=
new
FileStream
(
$@"
{
this
.
LogPath
}
\
{
fileName
}
"
,
FileMode
.
Open
,
FileAccess
.
Read
);
//
设定
this
.
AsyncUI
(()
=>
{
//
初始化进度条
this
.
AsyncUI
(()
=>
{
this
.
progressBar1
.
Maximum
=
Math
.
Max
(
1
,
(
int
)(
fs
.
Length
/
1024
));
this
.
progressBar1
.
Value
=
0
;
});
...
...
@@ -94,7 +148,7 @@ namespace Tools.UI
if
(
this
.
progressBar1
.
Value
<
this
.
progressBar1
.
Maximum
)
this
.
progressBar1
.
Value
+=
1
;
});
sb
.
Append
(
isDefault
?
Encoding
.
Default
.
GetString
(
buffer
)
:
Encoding
.
UTF8
.
GetString
(
buffer
));
sb
.
Append
(
encode
.
GetString
(
buffer
));
}
//显示日志内容
this
.
AsyncUI
(()
=>
this
.
textBox1
.
Text
=
sb
.
ToString
());
...
...
@@ -103,31 +157,5 @@ namespace Tools.UI
fs
.
Close
();
},
token
);
}
/// <summary>
/// 日志文件类型(兼容原有的txt日志和log4net日志)
/// </summary>
List
<
string
>
LogExtensions
=
new
List
<
string
>
{
".txt"
,
".log"
};
/// <summary>
/// 初始化列表框
/// </summary>
private
void
InitListBox
()
{
//清空原有项
this
.
textBox1
.
Text
=
string
.
Empty
;
this
.
listBox1
.
Items
.
Clear
();
//重新加载
if
(
Directory
.
Exists
(
this
.
LogPath
))
{
var
dirInfo
=
new
DirectoryInfo
(
this
.
LogPath
);
var
files
=
dirInfo
.
GetFiles
().
Where
(
f
=>
this
.
LogExtensions
.
Contains
(
f
.
Extension
.
ToLower
())).
Select
(
f
=>
f
.
Name
);
this
.
listBox1
.
Items
.
AddRange
(
files
.
ToArray
());
}
else
{
Utils
.
Tip
(
"路径不存在,请检查!"
);
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment