在控制台应用程序reg中配置log4net [英] Configuring log4net in console application reg

查看:104
本文介绍了在控制台应用程序reg中配置log4net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我已经成功使用控制台应用程序配置了log4net.

但是,在构建并获取包含log4net支持文件和app.config文件的dll并将其放置在新项目中后

如果我运行该新项目日志不起作用,但该dll中的另一个概念正常工作

我不知道我在哪里犯错了

关于该错误,您能帮我吗

等待您的回应

我生成的应用程序配置是

Hi
I have configure log4net with a console application successfully .

But after building and taking the dll with supportive files of log4net and app.config file and place it in a new project

if i run that new project log is not working but the other concept in that dll works fine

i do not know where i commited mistake

Can u help me regarding that error

Waiting for your response

my app config generated is

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
  </configSections>
  <log4net>
    <!--
  This writes the log information to the console window.  It only logs events
  that are at least at the INFO level (which would mean that DEBUG events are not
  captured.
  -->
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date{ABSOLUTE} [%thread] %level %logger - %message%newlineExtra Info: %property{testProperty}%newline%exception"/>
      </layout>
      <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="INFO"/>
        <levelMax value="FATAL"/>
      </filter>
    </appender>
    <!--
  This stores information in the mylogfile.txt file.  It only captures log events
  that contain the key word test or error.
  -->
    <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
      <file value="mylogfiles.txt"/>
      <appendToFile value="true"/>
      <rollingStyle value="Size"/>
      <maxSizeRollBackups value="5"/>
      <maximumFileSize value="10MB"/>
      <staticLogFileName value="true"/>

      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %level %logger - %message%newline%exception"/>
      </layout>
    </appender>
    <root>
      <level value="INFO"/>
      <appender-ref ref="RollingFileAppender"/>
    </root>
    <logger name="Log4NetTest.OtherClass">
      <level value="INFO"/>
      <appender-ref ref="ConsoleAppender"/>
    </logger>
  </log4net>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>




问候
Gowtham




Regards
Gowtham

推荐答案

如果我对您的理解正确,那么您可以在一个应用程序中测试所有内容,然后将配置和dll放入一个新的应用程序中,而现在一切正常.在我看来,您可能没有完成代码中需要做的所有工作.例如,您是否正确设置了GetLogger变量?您实际上是在打电话给记录器吗?

我真的不喜欢尝试复制整个配置.相反,我希望您仅复制所需的log4net部分.否则,您可以轻松地引入问题.

大约一年前,我写了一篇文章,逐步引导您了解log4net并解释了每个步骤.也许如果您逐步完成每个步骤,并将其与无法正常工作的应用程序进行比较,您会发现问题出在哪里.这是文章的链接:

log4net教程 [
If I understand you correctly, you tested everything out in one application and then put the config and the dll into a new application and now nothing works. It sounds to me like you might not have done all of the work in your code that you need to do. For example, did you set up your GetLogger variable correctly? Are you actually making any calls to the logger?

I''m really not a fan of trying to copy a whole config. Instead, I would rather see you copy just the log4net portion that you need. Otherwise, you can easily introduce issues.

I wrote an aricle about a year ago that walks you through log4net step by step and explains each step. Maybe if you walk through each step and compare it against your non-working application, you will see where the trouble is. Here is the link to the article:

log4net Tutorial[^]


这篇关于在控制台应用程序reg中配置log4net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆