1

I am using log4net – EventLogAppender to log the application errors to a custom log. This happens, but the errors are also logged in Application log. Since I have my own custom event log say myLog, is it possible to stop the errors being logged into default log Application?

<log4net debug="true">
  <appender name="sendAlertAppender" type="sendAlertAppender.MultiThresholdNotifyingAppender,sendAlertAppender">      
    <LevelThreshold  value="ERROR"/>      
  <appender-ref ref="EventLogAppender"/>
  </appender>

  <appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
    <param name="LogName" value="xxxWebLogs" />
    <param name="ApplicationName" value="xxx" />
    <eventId value="5" />
    <eventCategory value="10" />
    <filter type="log4net.Filter.LevelRangeFilter">
      <acceptOnMatch value="true" />
      <levelMin value="INFO" />
      <levelMax value="FATAL" />        
    </filter>
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
    </layout>
  </appender>
  <root>
    <level value="ALL"/>
    <priority value="DEBUG" />
    <appender-ref ref="sendAlertAppender"/>
    <appender-ref ref="EventLogAppender"/>
  </root>
</log4net>

enter image description here

Philipp M
  • 1,877
  • 7
  • 27
  • 38
Vani
  • 1,345
  • 4
  • 27
  • 48
  • Can you show your current log4net config? – Garrett Vlieger Dec 20 '11 at 19:48
  • if i understand correctly, you are asking how to log to the event log without logging to the event log. is that correct? if so, i think it's an absurd question. – Dave Rael Dec 20 '11 at 20:18
  • @Garret pls see the log4net.config settings. – Vani Dec 20 '11 at 20:21
  • @Dave My question is ,i have my own eventlog file and errors are logging there. By default the errors will go to application log,i want to stop that. – Vani Dec 20 '11 at 20:23
  • Based on your configuration, the `LogName` parameter should be setting the Event log location. Is it not working that way? – Garrett Vlieger Dec 20 '11 at 20:32
  • I am not sure whether i am explaining my problem in a right way. All the errors are getting logged in "xxxWebLogs" and it works fine. In addition it also logs the error in "Application" log[the default one].So i want to stop that. – Vani Dec 20 '11 at 20:38
  • @Garret the errors are logged into both PortalWeblogs and also Application log. Since i am logging in custom event viewer ,i don't want that in Application log. – Vani Dec 20 '11 at 20:45
  • @Vani - that's the clarification i wanted. i was confused by you saying you have your own event viewer. you were talking about having your own event log. – Dave Rael Dec 20 '11 at 20:48
  • @Dave.. I misused the words.. i am talking abt the own event log.. – Vani Dec 20 '11 at 20:58

2 Answers2

1

I'm still not sure what your issue is, but looking at the configuration I believe you need to change the LogName setting:

<param name="LogName" value="PortalWebLogs" />

If this doesn't work, it could be a permissions issue. See here for more information:

log4Net EventlogAppender does not work for Asp.Net 2.0 WebSite?

Community
  • 1
  • 1
Garrett Vlieger
  • 9,354
  • 4
  • 32
  • 44
  • The errors are logged into both PortalWeblogs and also Application log. Since i am logging in custom eventlog "PortalWeblogs" ,i don't want that in Application log.Pls see the attached image. – Vani Dec 20 '11 at 21:07
  • What's in the sendAlertAppender code? Is that possibly logging to the event log as well? – Garrett Vlieger Dec 20 '11 at 21:40
  • sendAlertAppender is extension of log4net for sending the alert emails. – Vani Dec 21 '11 at 19:33
0

I haven't done much with using the event log appender, so i'm not really sure. here's another question talking about it and in the answer, it shows using a logName element with a value attribute instead of a param element. might be worth trying that.

Configuring a custom event log for log4net

Community
  • 1
  • 1
Dave Rael
  • 1,759
  • 2
  • 16
  • 21