log
j是java開發人員所熟悉
他提供了強大的日志記錄功能
log
net是為
Net記錄日志開發的
使用示例如下(C#)
nfig文件
<?xml version=
encoding=
utf
?>
<configuration>
<appSettings>
<add key=
log
net
config
file
value=
nfig
/>
</appSettings>
</configuration>
nfig文件
<?xml version=
encoding=
utf
?>
<configuration>
<!
This section contains the log
net configuration settings
>
<log
net>
<!
Define some output appenders
>
<appender name=
RollingLogFileAppender
type=
log
net
Appender
RollingFileAppender
>
<param name=
File
value=
Log\\LQSS
SS
log
txt
/>
<param name=
AppendToFile
value=
true
/>
<param name=
MaxSizeRollBackups
value=
/>
<param name=
MaximumFileSize
value=
KB
/>
<param name=
RollingStyle
value=
Size
/>
<param name=
StaticLogFileName
value=
true
/>
<layout type=
log
net
Layout
PatternLayout
>
<param name=
Header
value=
[Header]\r\n
/>
<param name=
Footer
value=
[Footer]\r\n
/>
<param name=
ConversionPattern
value=
%d [%t] %
p %c [%x]
%m%n
/>
</layout>
</appender>
<appender name=
ConsoleAppender
type=
log
net
Appender
ConsoleAppender
>
<layout type=
log
net
Layout
PatternLayout
>
<param name=
ConversionPattern
value=
%d [%t] %
p %c [%x] <%X{auth}>
%m%n
/>
</layout>
</appender>
<!
Setup the root category
add the appenders and set the default level
>
<root>
<level value=
INFO
/>
<appender
ref ref=
RollingLogFileAppender
/>
</root>
<root>
<level value=
DEBUG
/>
<appender
ref ref=
ConsoleAppender
/>
</root>
</log
net>
</configuration>
代碼文件
using log
net;
using log
net
Config;
class Program
{
private static ILog logger = LogManager
GetLogger(System
Reflection
MethodBase
GetCurrentMethod()
DeclaringType);
/// <summary>
/// 應用程序的主入口點
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
DOMConfigurator
Configure(
new FileInfo(ConfigurationSettings
AppSettings[
log
net
config
file
]));
logger
Info(
Start application
);
Console
Writeline(
請按 <enter> 鍵退出
);
System
Console
ReadLine();
}
catch (Exception e)
{
logger
Info (e);
}
}
}
From:http://tw.wingwit.com/Article/program/Java/hx/201311/26351.html