Combined use of comon.logging and log4net

Source: Internet
Author: User

?

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

  1. <? XML version= "1.0"?>
  2. <configuration>
  3. ?? <configsections>
  4. ? ??? <sectionname= "Log4net" type="log4net." Config.log4netconfigurationsectionhandler, log4net "/>
  5. ???? <sectiongroupname= "common" >
  6. ?????? <sectionname= "Logging" type="Common.Logging.ConfigurationSectionHandler, common.logging"/>
  7. ???? </sectiongroup>
  8. ?? </configsections>
  9. ?? <common>
  10. ???? <logging>
  11. ?????? <factoryadaptertype= "Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1211 ">
  12. ???????? <argkey= "Configtype" Value="INLINE"/>
  13. ?????? </factoryadapter>
  14. ???? </Logging>
  15. ?? </Common>
  16. ?? <log4net>
  17. ???? <appendername= "Consoleappender" type="log4net." Appender.consoleappender ">
  18. ?????? <layouttype= "log4net. Layout.patternlayout ">
  19. ???????? <conversionpatternvalue= "%d [%t]%-5p%l-%m%n"/>
  20. ?????? </Layout>
  21. ???? </appender>
  22. ???? <appendername= "Eventlogappender" type="log4net." Appender.eventlogappender ">
  23. ?????? <layouttype= "log4net. Layout.patternlayout ">
  24. ???????? <conversionpatternvalue= "%d [%t]%-5p%l-%m%n"/>
  25. ?????? </Layout>
  26. ???? </appender>
  27. ???? <appendername= "Rollingfileappender" type="log4net." Appender.rollingfileappender ">
  28. ?????? <paramname= "File" Value="log/"/>
  29. ?????? <!--<datepattern value= "Yyyymmdd&quot;. txt&quot; "/>-->
  30. ?????? <appendtofileValue= "true"/>
  31. ?
  32. ?????? <!--make the rolling file name with the date and size-->
  33. ?????? <rollingstylevalue= "Composite"/>
  34. ?????? <datepatternvalue= "yyyy-mm-dd&quot;. txt&quot; " />
  35. ?????? <maxsizerollbackupsvalue= "/> "
  36. ?????? <maximumfilesizevalue= "2MB"/>
  37. ?
  38. ?????? <preservelogfilenameextensionValue= "true"/>
  39. ?????? <staticlogfilenameValue= "false"/>
  40. ?????? <layouttype= "log4net. Layout.patternlayout ">
  41. ???????? <paramname= "Conversionpattern" Value="%d%-5p%m%n"/>
  42. ?????? </Layout>
  43. ???? </appender>
  44. ???? <root>
  45. ?????? <levelValue= "DEBUG"/>
  46. ?????? <appender-refref= "Consoleappender"/>
  47. ?????? <appender-refref= "Rollingfileappender"/>
  48. ???? </root>
  49. ?? </log4net>
  50. ?? <runtime>
  51. ???? <assemblybindingxmlns= "urn:schemas-microsoft-com:asm.v1" >
  52. ?????? <dependentassembly>
  53. ???????? <assemblyidentityname= "Common.Logging.Core" PublicKeyToken="af08829b84f0328e"culture="neutral"/>
  54. ???????? <bindingredirectoldversion= "0.0.0.0-3.1.0.0" newversion="3.1.0.0"/>
  55. ?????? </dependentassembly>
  56. ?????? <dependentassembly>
  57. ???????? <assemblyidentityname= "Common.logging" PublicKeyToken="af08829b84f0328e"culture="neutral"/>
  58. ???????? <bindingredirectoldversion= "0.0.0.0-3.1.0.0" newversion="3.1.0.0"/>
  59. ?????? </dependentassembly>
  60. ???? </assemblybinding>
  61. ?? </Runtime>
  62. </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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.