Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
project8856
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
赵宇轩
project8856
Commits
1027f5f8
Commit
1027f5f8
authored
3 years ago
by
noberumotto
Browse files
Options
Downloads
Patches
Plain Diff
增加log服务
parent
c23e4611
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Core/Servicers/Instances/Logger.cs
+61
-0
61 additions, 0 deletions
Core/Servicers/Instances/Logger.cs
Core/Servicers/Interfaces/ILogger.cs
+15
-0
15 additions, 0 deletions
Core/Servicers/Interfaces/ILogger.cs
with
76 additions
and
0 deletions
Core/Servicers/Instances/Logger.cs
0 → 100644
+
61
−
0
View file @
1027f5f8
using
Core.Servicers.Interfaces
;
using
System
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.IO
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Core.Servicers.Instances
{
public
class
Logger
:
ILogger
{
private
static
readonly
object
writeLock
=
new
object
();
private
string
loggerName
;
private
enum
LogLevel
{
Info
,
Warn
,
Error
,
}
public
Logger
()
{
loggerName
=
Path
.
Combine
(
AppDomain
.
CurrentDomain
.
BaseDirectory
,
"Log"
,
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd"
)
+
".log"
);
}
public
void
Info
(
string
message
)
{
Save
(
Fromat
(
LogLevel
.
Info
,
message
));
}
public
void
Warn
(
string
message
)
{
Save
(
Fromat
(
LogLevel
.
Warn
,
message
));
}
public
void
Error
(
string
message
)
{
Save
(
Fromat
(
LogLevel
.
Error
,
message
));
}
private
string
Fromat
(
LogLevel
logLevel
,
string
message
)
{
string
logText
=
$"[
{
logLevel
.
ToString
()}
] [
{
DateTime
.
Now
.
ToString
(
"yyyy-MM-dd HH:mm:ss"
)}
] \r\n
{
message
}
\r\n------------------------\r\n\r\n"
;
Debug
.
WriteLine
(
logText
);
return
logText
;
}
private
void
Save
(
string
message
)
{
lock
(
writeLock
)
{
string
dir
=
Path
.
GetDirectoryName
(
loggerName
);
if
(!
Directory
.
Exists
(
dir
))
{
Directory
.
CreateDirectory
(
dir
);
}
File
.
AppendAllText
(
loggerName
,
message
);
}
}
}
}
This diff is collapsed.
Click to expand it.
Core/Servicers/Interfaces/ILogger.cs
0 → 100644
+
15
−
0
View file @
1027f5f8
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
Core.Servicers.Interfaces
{
public
interface
ILogger
{
void
Info
(
string
message
);
void
Warn
(
string
message
);
void
Error
(
string
message
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment