Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
netcoreplus
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
tsai
netcoreplus
Commits
02b7f3a3
Commit
02b7f3a3
authored
May 18, 2019
by
阿星Plus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Log4Net
parent
707e93cb
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
517 additions
and
0 deletions
+517
-0
Log4NetLogger.cs
src/Plus.Log4Net/Log4NetLogger.cs
+410
-0
Log4NetLoggerFactory.cs
src/Plus.Log4Net/Log4NetLoggerFactory.cs
+70
-0
LoggingFacilityExtensions.cs
src/Plus.Log4Net/LoggingFacilityExtensions.cs
+15
-0
Plus.Log4Net.csproj
src/Plus.Log4Net/Plus.Log4Net.csproj
+9
-0
PlusCastleLog4NetModule.cs
src/Plus.Log4Net/PlusCastleLog4NetModule.cs
+13
-0
No files found.
src/Plus.Log4Net/Log4NetLogger.cs
0 → 100644
View file @
02b7f3a3
using
log4net
;
using
log4net.Core
;
using
log4net.Util
;
using
System
;
using
System.Globalization
;
using
ILogger
=
Castle
.
Core
.
Logging
.
ILogger
;
namespace
Plus.Log4Net
{
/// <summary>
/// Log4NetLogger
/// </summary>
[
Serializable
]
public
class
Log4NetLogger
:
MarshalByRefObject
,
ILogger
{
private
static
readonly
Type
DeclaringType
=
typeof
(
Log4NetLogger
);
public
Log4NetLogger
(
log4net
.
Core
.
ILogger
logger
,
Log4NetLoggerFactory
factory
)
{
Logger
=
logger
;
Factory
=
factory
;
}
internal
Log4NetLogger
()
{
}
internal
Log4NetLogger
(
ILog
log
,
Log4NetLoggerFactory
factory
)
:
this
(
log
.
Logger
,
factory
)
{
}
public
bool
IsDebugEnabled
{
get
{
return
Logger
.
IsEnabledFor
(
Level
.
Debug
);
}
}
public
bool
IsErrorEnabled
{
get
{
return
Logger
.
IsEnabledFor
(
Level
.
Error
);
}
}
public
bool
IsFatalEnabled
{
get
{
return
Logger
.
IsEnabledFor
(
Level
.
Fatal
);
}
}
public
bool
IsInfoEnabled
{
get
{
return
Logger
.
IsEnabledFor
(
Level
.
Info
);
}
}
public
bool
IsWarnEnabled
{
get
{
return
Logger
.
IsEnabledFor
(
Level
.
Warn
);
}
}
protected
internal
Log4NetLoggerFactory
Factory
{
get
;
set
;
}
protected
internal
log4net
.
Core
.
ILogger
Logger
{
get
;
set
;
}
public
bool
IsTraceEnabled
=>
throw
new
NotImplementedException
();
public
override
string
ToString
()
{
return
Logger
.
ToString
();
}
public
virtual
global
::
Castle
.
Core
.
Logging
.
ILogger
CreateChildLogger
(
string
name
)
{
return
Factory
.
Create
(
Logger
.
Name
+
"."
+
name
);
}
public
void
Debug
(
string
message
)
{
if
(
IsDebugEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Debug
,
message
,
null
);
}
}
public
void
Debug
(
Func
<
string
>
messageFactory
)
{
if
(
IsDebugEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Debug
,
messageFactory
.
Invoke
(),
null
);
}
}
public
void
Debug
(
string
message
,
Exception
exception
)
{
if
(
IsDebugEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Debug
,
message
,
exception
);
}
}
public
void
DebugFormat
(
string
format
,
params
object
[]
args
)
{
if
(
IsDebugEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Debug
,
new
SystemStringFormat
(
CultureInfo
.
InvariantCulture
,
format
,
args
),
null
);
}
}
public
void
DebugFormat
(
Exception
exception
,
string
format
,
params
object
[]
args
)
{
if
(
IsDebugEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Debug
,
new
SystemStringFormat
(
CultureInfo
.
InvariantCulture
,
format
,
args
),
exception
);
}
}
public
void
DebugFormat
(
IFormatProvider
formatProvider
,
string
format
,
params
object
[]
args
)
{
if
(
IsDebugEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Debug
,
new
SystemStringFormat
(
formatProvider
,
format
,
args
),
null
);
}
}
public
void
DebugFormat
(
Exception
exception
,
IFormatProvider
formatProvider
,
string
format
,
params
object
[]
args
)
{
if
(
IsDebugEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Debug
,
new
SystemStringFormat
(
formatProvider
,
format
,
args
),
exception
);
}
}
public
void
Error
(
string
message
)
{
if
(
IsErrorEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Error
,
message
,
null
);
}
}
public
void
Error
(
Func
<
string
>
messageFactory
)
{
if
(
IsErrorEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Error
,
messageFactory
.
Invoke
(),
null
);
}
}
public
void
Error
(
string
message
,
Exception
exception
)
{
if
(
IsErrorEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Error
,
message
,
exception
);
}
}
public
void
ErrorFormat
(
string
format
,
params
object
[]
args
)
{
if
(
IsErrorEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Error
,
new
SystemStringFormat
(
CultureInfo
.
InvariantCulture
,
format
,
args
),
null
);
}
}
public
void
ErrorFormat
(
Exception
exception
,
string
format
,
params
object
[]
args
)
{
if
(
IsErrorEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Error
,
new
SystemStringFormat
(
CultureInfo
.
InvariantCulture
,
format
,
args
),
exception
);
}
}
public
void
ErrorFormat
(
IFormatProvider
formatProvider
,
string
format
,
params
object
[]
args
)
{
if
(
IsErrorEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Error
,
new
SystemStringFormat
(
formatProvider
,
format
,
args
),
null
);
}
}
public
void
ErrorFormat
(
Exception
exception
,
IFormatProvider
formatProvider
,
string
format
,
params
object
[]
args
)
{
if
(
IsErrorEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Error
,
new
SystemStringFormat
(
formatProvider
,
format
,
args
),
exception
);
}
}
public
void
Fatal
(
string
message
)
{
if
(
IsFatalEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Fatal
,
message
,
null
);
}
}
public
void
Fatal
(
Func
<
string
>
messageFactory
)
{
if
(
IsFatalEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Fatal
,
messageFactory
.
Invoke
(),
null
);
}
}
public
void
Fatal
(
string
message
,
Exception
exception
)
{
if
(
IsFatalEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Fatal
,
message
,
exception
);
}
}
public
void
FatalFormat
(
string
format
,
params
object
[]
args
)
{
if
(
IsFatalEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Fatal
,
new
SystemStringFormat
(
CultureInfo
.
InvariantCulture
,
format
,
args
),
null
);
}
}
public
void
FatalFormat
(
Exception
exception
,
string
format
,
params
object
[]
args
)
{
if
(
IsFatalEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Fatal
,
new
SystemStringFormat
(
CultureInfo
.
InvariantCulture
,
format
,
args
),
exception
);
}
}
public
void
FatalFormat
(
IFormatProvider
formatProvider
,
string
format
,
params
object
[]
args
)
{
if
(
IsFatalEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Fatal
,
new
SystemStringFormat
(
formatProvider
,
format
,
args
),
null
);
}
}
public
void
FatalFormat
(
Exception
exception
,
IFormatProvider
formatProvider
,
string
format
,
params
object
[]
args
)
{
if
(
IsFatalEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Fatal
,
new
SystemStringFormat
(
formatProvider
,
format
,
args
),
exception
);
}
}
public
void
Info
(
string
message
)
{
if
(
IsInfoEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Info
,
message
,
null
);
}
}
public
void
Info
(
Func
<
string
>
messageFactory
)
{
if
(
IsInfoEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Info
,
messageFactory
.
Invoke
(),
null
);
}
}
public
void
Info
(
string
message
,
Exception
exception
)
{
if
(
IsInfoEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Info
,
message
,
exception
);
}
}
public
void
InfoFormat
(
string
format
,
params
object
[]
args
)
{
if
(
IsInfoEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Info
,
new
SystemStringFormat
(
CultureInfo
.
InvariantCulture
,
format
,
args
),
null
);
}
}
public
void
InfoFormat
(
Exception
exception
,
string
format
,
params
object
[]
args
)
{
if
(
IsInfoEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Info
,
new
SystemStringFormat
(
CultureInfo
.
InvariantCulture
,
format
,
args
),
exception
);
}
}
public
void
InfoFormat
(
IFormatProvider
formatProvider
,
string
format
,
params
object
[]
args
)
{
if
(
IsInfoEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Info
,
new
SystemStringFormat
(
formatProvider
,
format
,
args
),
null
);
}
}
public
void
InfoFormat
(
Exception
exception
,
IFormatProvider
formatProvider
,
string
format
,
params
object
[]
args
)
{
if
(
IsInfoEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Info
,
new
SystemStringFormat
(
formatProvider
,
format
,
args
),
exception
);
}
}
public
void
Trace
(
string
message
)
{
if
(
IsDebugEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Trace
,
message
,
null
);
}
}
public
void
Trace
(
Func
<
string
>
messageFactory
)
{
if
(
IsDebugEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Trace
,
messageFactory
.
Invoke
(),
null
);
}
}
public
void
Trace
(
string
message
,
Exception
exception
)
{
if
(
IsTraceEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Trace
,
message
,
exception
);
}
}
public
void
TraceFormat
(
string
format
,
params
object
[]
args
)
{
if
(
IsTraceEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Trace
,
new
SystemStringFormat
(
CultureInfo
.
InvariantCulture
,
format
,
args
),
null
);
}
}
public
void
TraceFormat
(
Exception
exception
,
string
format
,
params
object
[]
args
)
{
if
(
IsTraceEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Trace
,
new
SystemStringFormat
(
CultureInfo
.
InvariantCulture
,
format
,
args
),
exception
);
}
}
public
void
TraceFormat
(
IFormatProvider
formatProvider
,
string
format
,
params
object
[]
args
)
{
if
(
IsTraceEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Trace
,
new
SystemStringFormat
(
formatProvider
,
format
,
args
),
null
);
}
}
public
void
TraceFormat
(
Exception
exception
,
IFormatProvider
formatProvider
,
string
format
,
params
object
[]
args
)
{
if
(
IsTraceEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Trace
,
new
SystemStringFormat
(
formatProvider
,
format
,
args
),
exception
);
}
}
public
void
Warn
(
string
message
)
{
if
(
IsWarnEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Warn
,
message
,
null
);
}
}
public
void
Warn
(
Func
<
string
>
messageFactory
)
{
if
(
IsWarnEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Warn
,
messageFactory
.
Invoke
(),
null
);
}
}
public
void
Warn
(
string
message
,
Exception
exception
)
{
if
(
IsWarnEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Warn
,
message
,
exception
);
}
}
public
void
WarnFormat
(
string
format
,
params
object
[]
args
)
{
if
(
IsWarnEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Warn
,
new
SystemStringFormat
(
CultureInfo
.
InvariantCulture
,
format
,
args
),
null
);
}
}
public
void
WarnFormat
(
Exception
exception
,
string
format
,
params
object
[]
args
)
{
if
(
IsWarnEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Warn
,
new
SystemStringFormat
(
CultureInfo
.
InvariantCulture
,
format
,
args
),
exception
);
}
}
public
void
WarnFormat
(
IFormatProvider
formatProvider
,
string
format
,
params
object
[]
args
)
{
if
(
IsWarnEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Warn
,
new
SystemStringFormat
(
formatProvider
,
format
,
args
),
null
);
}
}
public
void
WarnFormat
(
Exception
exception
,
IFormatProvider
formatProvider
,
string
format
,
params
object
[]
args
)
{
if
(
IsWarnEnabled
)
{
Logger
.
Log
(
DeclaringType
,
Level
.
Warn
,
new
SystemStringFormat
(
formatProvider
,
format
,
args
),
exception
);
}
}
}
}
\ No newline at end of file
src/Plus.Log4Net/Log4NetLoggerFactory.cs
0 → 100644
View file @
02b7f3a3
using
Castle.Core.Logging
;
using
log4net
;
using
log4net.Config
;
using
log4net.Repository
;
using
System
;
using
System.IO
;
using
System.Xml
;
namespace
Plus.Log4Net
{
/// <summary>
/// Log4NetLoggerFactory
/// </summary>
public
class
Log4NetLoggerFactory
:
AbstractLoggerFactory
{
internal
const
string
DefaultConfigFileName
=
"log4net.config"
;
private
readonly
ILoggerRepository
_loggerRepository
;
public
Log4NetLoggerFactory
()
:
this
(
DefaultConfigFileName
)
{
}
public
Log4NetLoggerFactory
(
string
configFileName
)
{
_loggerRepository
=
LogManager
.
CreateRepository
(
typeof
(
Log4NetLoggerFactory
).
GetAssembly
(),
typeof
(
log4net
.
Repository
.
Hierarchy
.
Hierarchy
)
);
var
log4NetConfig
=
new
XmlDocument
();
log4NetConfig
.
Load
(
File
.
OpenRead
(
configFileName
));
XmlConfigurator
.
Configure
(
_loggerRepository
,
log4NetConfig
[
"log4net"
]);
}
public
Log4NetLoggerFactory
(
string
configFileName
,
bool
reloadOnChange
)
{
_loggerRepository
=
LogManager
.
CreateRepository
(
typeof
(
Log4NetLoggerFactory
).
GetAssembly
(),
typeof
(
log4net
.
Repository
.
Hierarchy
.
Hierarchy
)
);
if
(
reloadOnChange
)
{
XmlConfigurator
.
ConfigureAndWatch
(
_loggerRepository
,
new
FileInfo
(
configFileName
));
}
else
{
var
log4NetConfig
=
new
XmlDocument
();
log4NetConfig
.
Load
(
File
.
OpenRead
(
configFileName
));
XmlConfigurator
.
Configure
(
_loggerRepository
,
log4NetConfig
[
"log4net"
]);
}
}
public
override
ILogger
Create
(
string
name
)
{
if
(
name
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
name
));
}
return
new
Log4NetLogger
(
LogManager
.
GetLogger
(
_loggerRepository
.
Name
,
name
),
this
);
}
public
override
ILogger
Create
(
string
name
,
LoggerLevel
level
)
{
throw
new
NotSupportedException
(
"Logger levels cannot be set at runtime. Please review your configuration file."
);
}
}
}
\ No newline at end of file
src/Plus.Log4Net/LoggingFacilityExtensions.cs
0 → 100644
View file @
02b7f3a3
using
Castle.Facilities.Logging
;
namespace
Plus.Log4Net
{
/// <summary>
/// LoggingFacilityExtensions
/// </summary>
public
static
class
LoggingFacilityExtensions
{
public
static
LoggingFacility
UseLog4Net
(
this
LoggingFacility
loggingFacility
)
{
return
loggingFacility
.
LogUsing
<
Log4NetLoggerFactory
>();
}
}
}
\ No newline at end of file
src/Plus.Log4Net/Plus.Log4Net.csproj
View file @
02b7f3a3
...
@@ -4,4 +4,13 @@
...
@@ -4,4 +4,13 @@
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Castle.LoggingFacility" Version="5.0.0" />
<PackageReference Include="log4net" Version="2.0.8" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Plus\Plus.csproj" />
</ItemGroup>
</Project>
</Project>
src/Plus.Log4Net/PlusCastleLog4NetModule.cs
0 → 100644
View file @
02b7f3a3
using
Plus.Modules
;
namespace
Plus.Log4Net
{
/// <summary>
/// Castle Log4Net module
/// </summary>
[
DependsOn
(
typeof
(
PlusLeadershipModule
))]
public
class
PlusCastleLog4NetModule
{
}
}
\ No newline at end of file
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