-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from CanalSharp/dev
Add NLog & Microsoft log support.
- Loading branch information
Showing
29 changed files
with
325 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> | ||
|
||
<targets> | ||
<target name="asyncFile" xsi:type="AsyncWrapper"> | ||
<target name="log_file" xsi:type="File" | ||
fileName="${basedir}/Logs/${shortdate}/${logger}-${level}-${shortdate}.txt" | ||
layout="${longdate} | ${message} ${onexception:${exception:format=message} ${newline} ${stacktrace} ${newline}" | ||
archiveFileName="${basedir}/archives/${logger}-${level}-${shortdate}-{#####}.txt" | ||
archiveAboveSize="102400" | ||
archiveNumbering="Sequence" | ||
concurrentWrites="true" | ||
keepFileOpen="false" /> | ||
</target> | ||
<target name="console" xsi:type="ColoredConsole" layout="[${date:format=HH\:mm\:ss}]:${message} ${exception:format=message}" /> | ||
</targets> | ||
|
||
<rules> | ||
<logger name="*" minlevel="Debug" writeTo="asyncFile" /> | ||
<logger name="*" minlevel="Debug" writeTo="console" /> | ||
</rules> | ||
</nlog> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
|
||
namespace CanalSharp.Common.Logging | ||
{ | ||
public static class CanalSharpLogManager | ||
{ | ||
private static readonly ICanalSharpLoggerFactory DefaultLoggerFactory = new CanalSharpNullLoggerFactory(); | ||
private static ICanalSharpLoggerFactory _loggerFactory; | ||
|
||
public static ICanalSharpLogger GetLogger(Type type) | ||
{ | ||
var loggerFactory = _loggerFactory ?? DefaultLoggerFactory; | ||
return loggerFactory.CreateLogger(type); | ||
} | ||
|
||
public static ICanalSharpLogger GetLogger<T>() | ||
{ | ||
return GetLogger(typeof(T)); | ||
} | ||
|
||
public static void SetLoggerFactory(ICanalSharpLoggerFactory loggerFactory) | ||
{ | ||
_loggerFactory = loggerFactory; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
using System; | ||
|
||
namespace CanalSharp.Common.Logging | ||
{ | ||
internal class CanalSharpNullLogger : ICanalSharpLogger | ||
{ | ||
public void Debug(string message) | ||
{ | ||
} | ||
|
||
public void Info(string message) | ||
{ | ||
} | ||
|
||
public void Warning(string message) | ||
{ | ||
} | ||
|
||
public void Error(string message, System.Exception exception) | ||
{ | ||
} | ||
|
||
public void Trace(string message) | ||
{ | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/CanalSharp.Common/Logging/CanalSharpNullLoggerFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System; | ||
|
||
namespace CanalSharp.Common.Logging | ||
{ | ||
public class CanalSharpNullLoggerFactory : ICanalSharpLoggerFactory | ||
{ | ||
public ICanalSharpLogger CreateLogger(Type type) | ||
{ | ||
return new CanalSharpNullLogger(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
| ||
namespace CanalSharp.Common.Logging | ||
{ | ||
public interface ICanalSharpLogger | ||
{ | ||
void Debug(string message); | ||
|
||
void Info(string message); | ||
|
||
void Warning(string message); | ||
|
||
void Error(string message, System.Exception exception); | ||
|
||
void Trace(string message); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System; | ||
|
||
namespace CanalSharp.Common.Logging | ||
{ | ||
public interface ICanalSharpLoggerFactory | ||
{ | ||
ICanalSharpLogger CreateLogger(Type type); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.