This repository has been archived by the owner on Feb 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
192 additions
and
6 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
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,39 @@ | ||
using log4net.Config; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace LiaoTian_Cup.Helper | ||
{ | ||
public class LogHelper | ||
{ | ||
public static readonly log4net.ILog loginfo = log4net.LogManager.GetLogger("loginfo"); | ||
public static readonly log4net.ILog logerror = log4net.LogManager.GetLogger("logerror"); | ||
|
||
public static void InitLog4Net() | ||
{ | ||
var logCfg = new FileInfo(AppDomain.CurrentDomain.BaseDirectory + "log4net.config"); | ||
XmlConfigurator.ConfigureAndWatch(logCfg); | ||
loginfo.Info("----- 日志初始化 -----"); | ||
} | ||
|
||
public static void WriteInfoLog(string info) | ||
{ | ||
if (loginfo.IsInfoEnabled) | ||
{ | ||
loginfo.Info(info); | ||
} | ||
} | ||
|
||
public static void WriteErrLog(string info, Exception ex) | ||
{ | ||
if (logerror.IsErrorEnabled) | ||
{ | ||
logerror.Error(info, ex); | ||
} | ||
} | ||
} | ||
} |
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,54 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<log4net> | ||
<!--错误日志类--> | ||
<logger name="logerror"> | ||
<!--日志类的名字--> | ||
<level value="ALL" /> | ||
<!--定义记录的日志级别--> | ||
<appender-ref ref="ErrorAppender" /> | ||
<!--记录到哪个介质中去--> | ||
</logger> | ||
<!--信息日志类--> | ||
<logger name="loginfo"> | ||
<level value="ALL" /> | ||
<appender-ref ref="InfoAppender" /> | ||
</logger> | ||
<!--错误日志附加介质--> | ||
<appender name="ErrorAppender" type="log4net.Appender.RollingFileAppender"> | ||
<!-- name属性指定其名称,type则是log4net.Appender命名空间的一个类的名称,意思是,指定使用哪种介质--> | ||
<param name="File" value="Logs\\LogError\\" /> | ||
<!--日志输出到exe程序这个相对目录下--> | ||
<param name="AppendToFile" value="true" /> | ||
<!--输出的日志不会覆盖以前的信息--> | ||
<param name="MaxSizeRollBackups" value="100" /> | ||
<!--备份文件的个数--> | ||
<param name="MaxFileSize" value="10240" /> | ||
<!--当个日志文件的最大大小--> | ||
<param name="StaticLogFileName" value="false" /> | ||
<!--是否使用静态文件名--> | ||
<param name="DatePattern" value="yyyyMMdd".htm"" /> | ||
<!--日志文件名--> | ||
<param name="RollingStyle" value="Date" /> | ||
<!--文件创建的方式,这里是以Date方式创建--> | ||
<!--错误日志布局--> | ||
<layout type="log4net.Layout.PatternLayout"> | ||
<param name="ConversionPattern" value="<HR COLOR=red>%n异常时间:%d [%t] <BR>%n异常级别:%-5p <BR>%n异 常 类:%c [%x] <BR>%n%m <BR>%n" /> | ||
</layout> | ||
</appender> | ||
<!--信息日志附加介质--> | ||
<appender name="InfoAppender" type="log4net.Appender.RollingFileAppender"> | ||
<param name="File" value="Logs\\LogInfo\\" /> | ||
<param name="AppendToFile" value="true" /> | ||
<param name="MaxFileSize" value="10240" /> | ||
<param name="MaxSizeRollBackups" value="100" /> | ||
<param name="StaticLogFileName" value="false" /> | ||
<param name="DatePattern" value="yyyyMMdd".htm"" /> | ||
<param name="RollingStyle" value="Date" /> | ||
<!--信息日志布局--> | ||
<layout type="log4net.Layout.PatternLayout"> | ||
<param name="ConversionPattern" value="<HR COLOR=blue>%n日志时间:%d [%t] <BR>%n日志级别:%-5p <BR>%n日 志 类:%c [%x] <BR>%n%m <BR>%n" /> | ||
</layout> | ||
</appender> | ||
</log4net> | ||
</configuration> |