logj是java开发人员所熟悉他提供了强大的日志记录功能lognet是为Net记录日志开发的使用示例如下(C#)
nfig文件
<?xml version= encoding=utf ?>
<configuration>
<appSettings>
<add key=lognetconfigfile value=nfig/>
</appSettings>
</configuration>
nfig文件
<?xml version= encoding=utf ?>
<configuration>
<! This section contains the lognet configuration settings >
<lognet>
<! Define some output appenders >
<appender name=RollingLogFileAppender type=lognetAppenderRollingFileAppender>
<param name=File value=Log\\LQSSSSlogtxt />
<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=lognetLayoutPatternLayout>
<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=lognetAppenderConsoleAppender>
<layout type=lognetLayoutPatternLayout>
<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 />
<appenderref ref=RollingLogFileAppender />
</root>
<root>
<level value=DEBUG />
<appenderref ref=ConsoleAppender />
</root>
</lognet>
</configuration>
代码文件
using lognet;
using lognetConfig;
class Program
{
private static ILog logger = LogManagerGetLogger(SystemReflectionMethodBaseGetCurrentMethod()DeclaringType);
/// <summary>
/// 应用程序的主入口点
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
DOMConfiguratorConfigure(
new FileInfo(ConfigurationSettingsAppSettings[lognetconfigfile]));
loggerInfo(Start application);
ConsoleWriteline(请按 <enter> 键退出);
SystemConsoleReadLine();
}
catch (Exception e)
{
loggerInfo (e);
}
}
}