?
1. Summary
Common.logging defines a common interface for an interface, especially as an interface-type component in Quartz.net, and uses components such as Log4net,nlog.
?
2. Steps to use
Install-package common.logging |
Install the Public log component |
Install-package log4net |
Installing Log4net |
Install-package Common.Logging.Log4Net1211 |
Ann Log4net's adaptation library for common.logging |
?
?
3. Configuration files
Note the Bold section
- <? XML version= "1.0"?>
- <configuration>
- ?? <configsections>
- ? ??? <sectionname= "Log4net" type="log4net." Config.log4netconfigurationsectionhandler, log4net "/>
- ???? <sectiongroupname= "common" >
- ?????? <sectionname= "Logging" type="Common.Logging.ConfigurationSectionHandler, common.logging"/>
- ???? </sectiongroup>
- ?? </configsections>
- ?? <common>
- ???? <logging>
- ?????? <factoryadaptertype= "Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1211 ">
- ???????? <argkey= "Configtype" Value="INLINE"/>
- ?????? </factoryadapter>
- ???? </Logging>
- ?? </Common>
- ?? <log4net>
- ???? <appendername= "Consoleappender" type="log4net." Appender.consoleappender ">
- ?????? <layouttype= "log4net. Layout.patternlayout ">
- ???????? <conversionpatternvalue= "%d [%t]%-5p%l-%m%n"/>
- ?????? </Layout>
- ???? </appender>
- ???? <appendername= "Eventlogappender" type="log4net." Appender.eventlogappender ">
- ?????? <layouttype= "log4net. Layout.patternlayout ">
- ???????? <conversionpatternvalue= "%d [%t]%-5p%l-%m%n"/>
- ?????? </Layout>
- ???? </appender>
- ???? <appendername= "Rollingfileappender" type="log4net." Appender.rollingfileappender ">
- ?????? <paramname= "File" Value="log/"/>
- ?????? <!--<datepattern value= "Yyyymmdd". txt" "/>-->
- ?????? <appendtofileValue= "true"/>
- ?
- ?????? <!--make the rolling file name with the date and size-->
- ?????? <rollingstylevalue= "Composite"/>
- ?????? <datepatternvalue= "yyyy-mm-dd". txt" " />
- ?????? <maxsizerollbackupsvalue= "/> "
- ?????? <maximumfilesizevalue= "2MB"/>
- ?
- ?????? <preservelogfilenameextensionValue= "true"/>
- ?????? <staticlogfilenameValue= "false"/>
- ?????? <layouttype= "log4net. Layout.patternlayout ">
- ???????? <paramname= "Conversionpattern" Value="%d%-5p%m%n"/>
- ?????? </Layout>
- ???? </appender>
- ???? <root>
- ?????? <levelValue= "DEBUG"/>
- ?????? <appender-refref= "Consoleappender"/>
- ?????? <appender-refref= "Rollingfileappender"/>
- ???? </root>
- ?? </log4net>
- ?? <runtime>
- ???? <assemblybindingxmlns= "urn:schemas-microsoft-com:asm.v1" >
- ?????? <dependentassembly>
- ???????? <assemblyidentityname= "Common.Logging.Core" PublicKeyToken="af08829b84f0328e"culture="neutral"/>
- ???????? <bindingredirectoldversion= "0.0.0.0-3.1.0.0" newversion="3.1.0.0"/>
- ?????? </dependentassembly>
- ?????? <dependentassembly>
- ???????? <assemblyidentityname= "Common.logging" PublicKeyToken="af08829b84f0328e"culture="neutral"/>
- ???????? <bindingredirectoldversion= "0.0.0.0-3.1.0.0" newversion="3.1.0.0"/>
- ?????? </dependentassembly>
- ???? </assemblybinding>
- ?? </Runtime>
- </configuration>
?
4. Sample Code
Using common.logging;
。。。。。。
ILog log = Logmanager. GetLogger (type);
If (log. isdebugenabled)
{
String StrText = GetMessage ("DEBUG", ClassName, methodName, message);
Log. Debug (StrText);
}
。。。。。。
Combined use of comon.logging and log4net