首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Common.Logging支持日志到文件。

Common.Logging支持日志到文件。
EN

Stack Overflow用户
提问于 2013-05-06 20:00:12
回答 1查看 10.9K关注 0票数 3

我在查阅有关普通日志记录的文档时,没有注意到除了利用其他日志技术(如Log4Net、企业库、Nlog等)之外,对日志文件写入日志文件的任何支持。我只是想知道是否有人知道如何将common.logging配置为写入文件,或者是否必须回到包装在Common.Logging中的另一种日志技术。

EN

回答 1

Stack Overflow用户

发布于 2013-05-06 20:17:30

您可以选择用于公共日志记录的特定日志记录框架,并将其配置为将日志记录为文件。例如,如果您想在公共日志记录中使用log4net,您可能有一个配置文件,如下所示:

代码语言:javascript
复制
<?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>
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/16406296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档