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
d030e71b
Commit
d030e71b
authored
Dec 03, 2021
by
段廷瑞
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1、添加日志功能
parent
b70b1366
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
213 additions
and
11 deletions
+213
-11
Ftt.PatchPack.exe.config
AppHome/Ftt.PatchPack.exe.config
+0
-2
Tools.exe.config
AppHome/Tools.exe.config
+1
-1
Log.cs
Tools/MyCommon/Log.cs
+203
-0
UserLog.cs
Tools/MyCommon/UserLog.cs
+3
-3
Tools.csproj
Tools/Tools.csproj
+2
-1
wMain.cs
Tools/wMain.cs
+4
-4
No files found.
AppHome/Ftt.PatchPack.exe.config
View file @
d030e71b
...
@@ -9,8 +9,6 @@
...
@@ -9,8 +9,6 @@
<
add
key
=
"PatchTimeFrame_Sql"
value
=
"720"
/>
<
add
key
=
"PatchTimeFrame_Sql"
value
=
"720"
/>
<
add
key
=
"PatchTimeFrame_Xml"
value
=
"720"
/>
<
add
key
=
"PatchTimeFrame_Xml"
value
=
"720"
/>
<
add
key
=
"PatchTimeFrame_Xml"
value
=
"720"
/>
<!--是否排除.
pdb
文件。
1
:排除,其他包含。-->
<!--是否排除.
pdb
文件。
1
:排除,其他包含。-->
<
add
key
=
"Exclude_PDB"
value
=
"1"
/>
<
add
key
=
"Exclude_PDB"
value
=
"1"
/>
<
add
key
=
"ClientSettingsProvider.ServiceUri"
value
=
""
/>
<
add
key
=
"ClientSettingsProvider.ServiceUri"
value
=
""
/>
...
...
AppHome/Tools.exe.config
View file @
d030e71b
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
<
appSettings
>
<
appSettings
>
<
add
key
=
"LoginInfo"
value
=
"wwF/xpBzWek="
/>
<
add
key
=
"LoginInfo"
value
=
"wwF/xpBzWek="
/>
<
add
key
=
"LoginVerify"
value
=
"v86f5Q3Xa7U="
/>
<
add
key
=
"LoginVerify"
value
=
"v86f5Q3Xa7U="
/>
<
add
key
=
"UpdateTime"
value
=
"2021-1
1-26 16:12:01.887
"
/>
<
add
key
=
"UpdateTime"
value
=
"2021-1
2-01 16:00:39.650
"
/>
</
appSettings
>
</
appSettings
>
<
startup
>
<
startup
>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.8"
/>
<
supportedRuntime
version
=
"v4.0"
sku
=
".NETFramework,Version=v4.8"
/>
...
...
Tools/MyCommon/Log.cs
0 → 100644
View file @
d030e71b
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
FTT.Core
{
/// <summary>
/// 日志
/// </summary>
public
sealed
class
Log
{
/// <summary>
/// 调试
/// </summary>
/// <param name="msg"></param>
public
static
void
Debug
(
object
obj
)
{
Write
(
obj
,
nameof
(
Debug
));
}
/// <summary>
/// 错误
/// </summary>
/// <param name="msg"></param>
public
static
void
Error
(
object
obj
)
{
Write
(
obj
,
nameof
(
Error
));
}
/// <summary>
/// 信息
/// </summary>
/// <param name="obj">消息对象</param>
/// <param name="title">自定义标题</param>
public
static
void
Info
(
object
obj
,
string
title
=
"Info"
)
{
Write
(
obj
,
title
);
}
/// <summary>
/// 警告
/// </summary>
/// <param name="msg"></param>
public
static
void
Warn
(
object
obj
)
{
Write
(
obj
,
nameof
(
Warn
));
}
/// <summary>
/// [并发]锁对象
/// </summary>
private
static
object
_locker
=
new
object
();
/// <summary>
/// [异步]写入日志
/// </summary>
/// <param name="obj">消息对象</param>
/// <param name="category">消息类别</param>
private
static
void
Write
(
object
obj
,
string
category
)
{
lock
(
_locker
)
{
try
{
Task
.
Run
(()
=>
Loger
.
Instance
.
Write
(
obj
,
category
));
}
finally
{
Monitor
.
Pulse
(
_locker
);
}
}
}
}
/// <summary>
/// 日志(单例)
/// </summary>
public
class
Loger
{
private
static
Loger
_instance
=
null
;
/// <summary>
/// 单例
/// </summary>
public
static
Loger
Instance
{
get
{
if
(
_instance
==
null
)
_instance
=
new
Loger
();
return
_instance
;
}
}
/// <summary>
/// 私有:构造方法
/// </summary>
private
Loger
()
{
//清除监听器
Trace
.
Listeners
.
Clear
();
//通过自定义监听器,监听消息并记录日志
Trace
.
Listeners
.
Add
(
new
LogerTraceListener
());
}
/// <summary>
/// 写入日志
/// </summary>
/// <param name="msg"></param>
/// <param name="category"></param>
public
void
Write
(
object
obj
,
string
category
)
{
Trace
.
WriteLine
(
obj
,
category
);
}
}
/// <summary>
/// 日志记录监听器
/// </summary>
public
class
LogerTraceListener
:
TraceListener
{
private
string
_fileName
;
public
LogerTraceListener
()
{
//日志路径初始化
string
logPath
=
$@"
{
AppDomain
.
CurrentDomain
.
BaseDirectory
}
\Logs"
;
if
(!
Directory
.
Exists
(
logPath
))
Directory
.
CreateDirectory
(
logPath
);
this
.
_fileName
=
$@"
{
logPath
}
\Log-
{
DateTime
.
Now
.
ToString
(
"yyyyMMdd"
)}
.txt"
;
}
public
override
void
Write
(
string
message
)
{
this
.
WriteLogFile
(
message
);
}
public
override
void
Write
(
object
obj
)
{
this
.
WriteLogFile
(
obj
);
}
public
override
void
Write
(
string
message
,
string
category
)
{
this
.
WriteLogFile
(
message
,
category
);
}
public
override
void
Write
(
object
obj
,
string
category
)
{
this
.
WriteLogFile
(
obj
,
category
);
}
public
override
void
WriteLine
(
string
message
)
{
this
.
WriteLogFile
(
message
);
}
public
override
void
WriteLine
(
object
obj
)
{
this
.
WriteLogFile
(
obj
);
}
public
override
void
WriteLine
(
string
message
,
string
category
)
{
this
.
WriteLogFile
(
message
,
category
);
}
public
override
void
WriteLine
(
object
obj
,
string
category
)
{
this
.
WriteLogFile
(
obj
,
category
);
}
/// <summary>
/// 写入日志文件
/// </summary>
/// <param name="obj"></param>
/// <param name="category"></param>
private
void
WriteLogFile
(
object
obj
,
string
category
=
""
)
{
var
message
=
this
.
Format
(
obj
,
category
);
File
.
AppendAllText
(
_fileName
,
message
);
}
/// <summary>
/// 格式化消息对象
/// </summary>
/// <param name="obj"></param>
/// <param name="category"></param>
/// <returns></returns>
private
string
Format
(
object
obj
,
string
category
)
{
StringBuilder
builder
=
new
StringBuilder
();
//添加类别,格式:[类别名称] 日期 消息体
if
(!
string
.
IsNullOrEmpty
(
category
))
builder
.
AppendFormat
(
"[{0}] "
,
category
);
//添加日期
builder
.
AppendFormat
(
"{0} "
,
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
));
//构建消息体
if
(
obj
is
Exception
)
{
var
ex
=
(
Exception
)
obj
;
builder
.
Append
(
ex
.
Message
+
"\r\n"
);
builder
.
Append
(
ex
.
StackTrace
+
"\r\n"
);
}
else
{
builder
.
Append
(
obj
.
ToString
()
+
"\r\n"
);
}
return
builder
.
ToString
();
}
}
}
Tools/Log.cs
→
Tools/
MyCommon/User
Log.cs
View file @
d030e71b
...
@@ -9,12 +9,12 @@ using Tools.MyCommon;
...
@@ -9,12 +9,12 @@ using Tools.MyCommon;
using
Tools.MyData
;
using
Tools.MyData
;
using
Tools.MyUtils
;
using
Tools.MyUtils
;
namespace
Tools
namespace
Tools
.MyCommon
{
{
/// <summary>
/// <summary>
/// 日志
///
用户
日志
/// </summary>
/// </summary>
public
class
Log
public
class
User
Log
{
{
/// <summary>
/// <summary>
/// 数据库访问对象
/// 数据库访问对象
...
...
Tools/Tools.csproj
View file @
d030e71b
...
@@ -74,7 +74,8 @@
...
@@ -74,7 +74,8 @@
<Reference
Include=
"System.Xml"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Compile
Include=
"Log.cs"
/>
<Compile
Include=
"MyCommon\Log.cs"
/>
<Compile
Include=
"MyCommon\UserLog.cs"
/>
<Compile
Include=
"MyCommon\controls\MyTreeView.cs"
>
<Compile
Include=
"MyCommon\controls\MyTreeView.cs"
>
<SubType>
Component
</SubType>
<SubType>
Component
</SubType>
</Compile>
</Compile>
...
...
Tools/wMain.cs
View file @
d030e71b
...
@@ -98,7 +98,7 @@ namespace Tools
...
@@ -98,7 +98,7 @@ namespace Tools
this
.
lbSysVersion
.
Text
=
dt
.
DefaultView
.
Count
==
0
?
$"2021.0.1"
:
$"
{
dt
.
DefaultView
[
0
][
0
]}
"
;
this
.
lbSysVersion
.
Text
=
dt
.
DefaultView
.
Count
==
0
?
$"2021.0.1"
:
$"
{
dt
.
DefaultView
[
0
][
0
]}
"
;
}));
}));
//日志记录
//日志记录
Log
.
Write
(
"打开系统"
);
User
Log
.
Write
(
"打开系统"
);
}
}
private
void
WMain_FormClosing
(
object
sender
,
FormClosingEventArgs
e
)
private
void
WMain_FormClosing
(
object
sender
,
FormClosingEventArgs
e
)
{
{
...
@@ -324,7 +324,7 @@ namespace Tools
...
@@ -324,7 +324,7 @@ namespace Tools
return
;
return
;
}
}
//日志记录
//日志记录
Log
.
Write
(
"退出系统"
);
User
Log
.
Write
(
"退出系统"
);
//关闭窗体
//关闭窗体
this
.
Close
();
this
.
Close
();
}
}
...
@@ -399,7 +399,7 @@ namespace Tools
...
@@ -399,7 +399,7 @@ namespace Tools
frm
.
Show
();
frm
.
Show
();
}
}
//日志记录
//日志记录
Log
.
Write
(
$"打开模块:
{
page
.
Text
}
"
);
User
Log
.
Write
(
$"打开模块:
{
page
.
Text
}
"
);
//选中标签页
//选中标签页
this
.
tabControl1
.
SelectedTab
=
page
;
this
.
tabControl1
.
SelectedTab
=
page
;
page
.
Refresh
();
page
.
Refresh
();
...
@@ -412,7 +412,7 @@ namespace Tools
...
@@ -412,7 +412,7 @@ namespace Tools
{
{
if
(
page
.
Name
!=
nameof
(
HomePage
))
if
(
page
.
Name
!=
nameof
(
HomePage
))
{
{
Log
.
Write
(
$"关闭模块:
{
page
.
Text
}
"
);
//日志记录
User
Log
.
Write
(
$"关闭模块:
{
page
.
Text
}
"
);
//日志记录
this
.
OpenedList
.
Remove
(
page
.
Text
);
//移除列表
this
.
OpenedList
.
Remove
(
page
.
Text
);
//移除列表
this
.
tabControl1
.
TabPages
.
Remove
(
page
);
//移除页面
this
.
tabControl1
.
TabPages
.
Remove
(
page
);
//移除页面
page
.
Dispose
();
//释放页面
page
.
Dispose
();
//释放页面
...
...
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