I was looking through the documentation for common logging and didn't notice any support for writing to a log file outside of leveraging other logging technologies such as Log4Net, Enterprise library, Nlog etc. I just wanted to know if anyone knows of a way to configure Common.Logging to write to a file or if I have to fall back to another logging technology wrapped into common.logging.
Asked
Active
Viewed 1.1k times
3
-
3`Common.Logging` is just an abstraction layer over the different loggers. It just helps to decouple your application code from one specify logging framework. It cannot be used in a standalone fashion. You need to use some library NLog, log4net do the actual logging. – nemesv May 06 '13 at 20:03
-
Thanks that's what it looks like, I guess I'll use enterprise lib with Common.Logging. – crackhaus May 06 '13 at 20:08
-
Yes that's the whole point of the Common.Logging that you can decide later to which logging framework to use or you can even change it during run-time. – nemesv May 06 '13 at 20:10
-
14 years and no selected answer? – Peter Ritchie Mar 05 '17 at 02:05
1 Answers
6
You pick a particular logging framework to use with Common Logging and configure that for logging to file. For example, if you wanted to use log4net with Common Logging, you might have a config file that looks like this:
<?xml version="1.0"?>
<configuration>
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging"/>
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
<arg key="configType" value="INLINE"/>
</factoryAdapter>
</logging>
</common>
<log4net>
<appender name="FileAppender" type="log4net.Appender.FileAppender" >
<param name="File" value="log.txt" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %level %logger - %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="FileAppender" />
</root>
</log4net>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.1.2.0" newVersion="2.1.2.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.5.0.0" newVersion="4.5.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

Peter Ritchie
- 35,463
- 9
- 80
- 98