Tom Williams | 21 Feb 16:48 2014

Help needed with debugging AdoNetAppender

We’re using log4net 1.2.11 to log to a SQL Server database from an internal Windows service.   For the most part, log4net is working very well except for when SQL Server terminates the inactive log4net connection overnight.

 

I have the “reconnectonerror” property set to “true” in the log4net.config file but the database connection doesn’t appear to get re-established.

 

Anyway, I found how to enable log4net internal debugging and when I enable it, I get log messages but nothing from the AdoNetAppender.  I can see the AdoNetAppender being setup, but when I successfully log to the database using the AdoNetAppender, I get nothing in the debug output.  I also use a RollingFileAppender to log messages generated by our Windows service and I can see debug messages showing the log file getting rolled, per our RollingFileAppender configuration settings.

 

So, my questions are:

 

1)       How can I get internal debug output from the AdoNetAppender?

2)      What is the best way to debug failed attempts to reconnect to the SQL Server database?

 

We’re connecting to SQL Server 2008 and when things do work, log messages get logged in the database as desired.

 

Here is a snipet from our app.config file, which enables internal log4net debugging:

 

--------------  START  -----------------

 

<appSettings>

    …..

   <add key=”log4net.Internal.Debug” value=”true” />

</appSettings>

<system.diagnostics>

  <trace autoflush=”true”>

    <listeners>

       <add name=”textWriterTraceListener” type=”System.Diagnostics.TextWriterTraceListener” initializeData=”log4net-debug.log” />

    </listeners>

  </trace>

</system.diagnostics>

 

--------------  END --------------------

 

That creates a “log4net-debug.log” file that contains lots of info, once the Windows service has been running for a while.

 

Here is a snipet from our log4net.config file, which defines our appenders:

 

--------------  START  ------------------

<?xml version=”1.0” encoding=”utf-8” ?>

<configuration>

<log4net>

  <appender name=”RollingFile” type=”log4net.Appender.RollingFileAppender”>

     <file value=”service.log” />

    <appendToFile value=”true” />

    <maximumFileSize value=”100kb” />

    <maxSizeRollBackups value=”2” />

    <layout type=”log4net.Layout.PatternLayout”>

          <conversionPattern value=”%date [%thread] %-5level %a %logger = %message%newline” />

    </layout>

  </appender>

 

  <appender name=”ADONetAppender” type=”log4net.Appender.ADONetAppender”>

     <bufferSize value=”1” />

     <connectionType value=”System.Data.SqlClient.SqlConnection, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken={some string}” />

     <connectionString value=”{connection string for database connection}” />

     <commandText value=”{SQL INSERT statement to log data}” />

     <reconnectonerror value=”true” />

 

     <parameter>

         <parameterName value=” <at> application” />

        <dbType value=”String” />

        <size value=”100” />

        <layout type=”log4net.Layout.PatternLayout”>

           <conversionPattern value=”%appdomain” />

        </layout>

     </parameter>

 

(more parameters are defined similar to the above parameter)

  </appender>

 

  <root>

      <level value=”DEBUG” />

      <appender-ref ref=”RollingFile” />

  </root>

 

  <logger name=”DBLog”>

     <appender-ref ref=”ADONetAppender” />

  </logger>

</log4net>

</configuration>

--------------- END  --------------------

 

So, with the above settings, when I first start the Windows service, the log4net-debug.log file shows the creation of the appenders and it will eventually show the rolling of the log file.  I never see any messages from the ADONetAppender showing it logging messages to the database. 

 

Thanks!

 

Tom

The information contained in this electronic mail message is confidential information intended only for the use of the individual or entity named above. The information herein may also be protected by the Electronic Communications Privacy Act, 18 USC Sections 2510-2521. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify us by e-mail and delete the original message. In addition, to ensure compliance with requirements imposed by the IRS, we inform you that any U.S. tax advice contained in this communication (including any attachments) is not intended or written to be used, and cannot be used, for the purpose of (a) avoiding penalties under the Internal Revenue Code, or (b) promoting, marketing or recommending to another party any matters addressed in this communication. Thank you.

moonstone | 17 Feb 20:58 2014
Picon

how to keep 3 days of logs

I need to keep 3 days of logging information from my application, which runs
once per day.  For example, if I start with 3 days worth of logging
information retained:
CustomerDataTransfer.2014-02-15.txt
CustomerDataTransfer.2014-02-14.txt
CustomerDataTransfer.2014-02-13.txt

When I run the application on Feb 17, I'd like to have these 3 files
retained
CustomerDataTransfer.2014-02-17.txt
CustomerDataTransfer.2014-02-15.txt
CustomerDataTransfer.2014-02-14.txt

Is it possible to configure log4net this way?

Here's the configuration information I currently use.

    <appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender">

      
      <datePattern value="'.'yyyy-MM-dd'.txt'" />

      

      

      <layout type="log4net.Layout.PatternLayout">

        

      </layout>
    </appender>

--
View this message in context: http://apache-logging.6191.n7.nabble.com/how-to-keep-3-days-of-logs-tp44594.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

xaruman | 10 Feb 17:07 2014
Picon

Log4Net log into a remote C# App

Hi

I've been looking for a solution during several days but I've not found
anything. The issue is that I have an application which is saving logs by
log4net (a log file) and I need to "capture" this logs into a remote
application. I thought about mapping the log file into my remote
application, but I think that maybe there is a solution to my problem using
directly log4net functionality. 

Is it possible to "subscribe" remotely to a log4net logging? I mean, what I
need is that when A application prints a log into its log file, my B
application in a different computer advices this and display the information
in a win form. Remote append? a Server/client append? I have no idea about
how to fix this problem.

Thanks in advance for your help. Hope having been clear enough.

--
View this message in context: http://apache-logging.6191.n7.nabble.com/Log4Net-log-into-a-remote-C-App-tp44380.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Trent Cioran | 4 Feb 23:17 2014
Picon

Logging repositories

Hello All,

I have an advanced scenario for logging:

1) - I have an application which logs to default repository
2) - A manager thread that acts as a coordinator for the work to be done, this component should log to its own log file
3) - A processing thread that performs the actual work, this component will process X number of items so I want to log the component's activity to its own log so it is easier to troubleshoot in case of error and not mix with other processing threads output.
4) - An error log which should generate the detail for a specific processing item error 

Currently I have two appenders configured with filters so one logs to file DEBUG and INFO and the other logs only ERROR.

I am using a pattern string to specify the name of the log file like this: Processor_Mbx_%property{mbxId}_Seq_%property{seq}_%date{yyyyMMdd}.txt

I am using repositories in order to keep them separated and also to specify different configuration for each repository (for example manager thread only requires ,bxId and seq variables for the log file name while the item error requires these two and a third itemId. I am configuring my repositories using 

                var repository = LogManager.CreateRepository(repositoryName);

                XmlConfigurator.ConfigureAndWatch(repository, configFileInfo); // See sample at the bottom



These properties are set using the ThreadContext so each thread do not collide with the others. Log4net is generating the files as expected everything nice here, but the log goes to the first file that it created, for example, it creates files 

Processor_Mbx_1012_Seq_1_20140204.txt <--- logs are sent to this file
Processor_Mbx_1013_Seq_1_20140204.txt


I already tried using ThreadContext.Properties and ThreadContext.Stack but I get the same behaviour


Hope someone has an idea of why I am getting this behaviour and what I need to do to get the result I want.


Thanks in advance,
TrentCioran


----------------

Sample configuration file: 


<?xml version="1.0" encoding="utf-8" ?>

<log4net>

  <appender name="infoAppender" type="log4net.Appender.RollingFileAppender">

    <file type="log4net.Util.PatternString" value="C:\Logs\InfoLogs\Processor_Mbx_%property{mbxId}_%date{yyyyMMdd}.txt"/>

    <staticLogFileName value="true"/>

    <param name="appendToFile" value="true"/>

    <param name="maximumFileSize" value="10MB"/>

    <param name="maxSizeRollBackups" value="1000"/>

    <layout type="log4net.Layout.PatternLayout">

      <conversionPattern value="%date|[%thread]|%-5level|%logger|%property{NDC}|%message%newline"/>

    </layout>

    <filter type="log4net.Filter.LevelMatchFilter">

      <levelToMatch value="DEBUG"/>

    </filter>

    <filter type="log4net.Filter.DenyAllFilter"/>

  </appender>

  <appender name="errorAppender" type="log4net.Appender.RollingFileAppender">

    <threshold value="ERROR"/>

    <file type="log4net.Util.PatternString" value="C:\Logs\ErrorLogs\Processor_Mbx_%property{mbxId}_%date{yyyyMMdd}.txt"/>

    <staticLogFileName value="true"/>

    <param name="maximumFileSize" value="10MB"/>

    <param name="maxSizeRollBackups" value="1000"/>

    <layout type="log4net.Layout.PatternLayout">

      <conversionPattern value="%date|[%thread]|%-5level|%logger|%property{NDC}|%message%newline"/>

    </layout>

    <filter type="log4net.Filter.LevelMatchFilter">

      <levelToMatch value="ERROR"/>

    </filter>

    <filter type="log4net.Filter.DenyAllFilter"/>

  </appender>

  <root>

    <level value="DEBUG" />

    <appender-ref ref="errorAppender" />

    <appender-ref ref="infoAppender" />

  </root>

</log4net>




Picon

log4net filling memory in prod

Is there a way using log4net to limit the memory usage for logs?  The thread and private byte could goes out the window.  Also if trying to log to a path that the system doesn’t have rights it holds onto the events.  Is there a setting for simply dropping log entries that can’t be saved?

 

Thank you!

Douglas Neary | 14 Jan 23:36 2014

log4net rolling file appender losing log files during roll over

All:

 

Under heavy strain, I am seeing log4net lose log files during roll over.   I filed a bug yesterday (https://issues.apache.org/jira/browse/LOG4NET-416), and I wanted to offer my help (and hardware) to help track it down.  I attached the internal log4net log to the ticket.

 

The hardware we are using is pretty high end (http://www8.hp.com/us/en/products/proliant-servers/product-detail.html?oid=4231377#!tab=features).    We are using this beast as a combined image processor and web server, running IIS 7.5 on Windows Server 2008 R2. 

 

For every transaction processed, a line is written to log4net.   On average, we are probably doing around 7 transactions per second.  This works fine for a while, until it doesn’t.   Then it starts losing log files during rollover.

 

Given all the value we have gotten out of log4net, my company is willing to donate some of my time and some time on that DL980 to test out the fixes…

 

Is there anyone who can give me a push in the right direction?

 

Thanks,
Doug

Picon

Multiple processes logging to single file - unexplained error message

I am using log4net 1.2.10. It has been stated on this forum that from 1.2.9
onwards, different file locking schemas are available. I have configured
log4net as per examples given to use a non-default method (minimal-locking
or interprocess locking) but the immediate effect is the following error
message:

log4net:ERROR XmlHierarchyConfigurator: Cannot find Property [lockingModel]
to set object on
[log4net.Repository.Hierarchy.DefaultLoggerFactory+LoggerImpl]
log4net:ERROR [RollingFileAppender] Unable to acquire lock on file
C:\Program Files (x86)\Autoscribe\Matrix Gemini LIMS\Exe\log\Trace.log. The
process cannot access the file 'C:\Program Files (x86)\Autoscribe\Matrix
Gemini LIMS\Exe\log\Trace.log' because it is being used by another process.

My log4net.config file is:

		<logger name="Matrix.Trace">
			  
			<level value="OFF" />
			     <lockingModel type="log4net.Appender.FileAppender+InterProcessLock"
/>
			<appender-ref ref="RollingFileAppenderTRACE" />
		</logger>

		<appender name="RollingFileAppenderTRACE"
type="log4net.Appender.RollingFileAppender">
			<file value=".\log\Trace.log" />
			<layout type="log4net.Layout.PatternLayout">
				<conversionPattern value="%m%newline" />
			</layout>
			<appendToFile value="true" />
			<maximumFileSize value="100KB" />
			<maxSizeRollBackups value="2" />
		</appender>
etc...

My C# application does this:

        private static readonly ILog bllDebugLog =
LogManager.GetLogger("Matrix.Trace"); //for debugging

and

            log4net.Config.XmlConfigurator.ConfigureAndWatch(new
System.IO.FileInfo("log4net.config"));

If I use the default locking method, logging does work (but I have file-lock
problems with multiple processes, which is what I am trying to resolve).

I cannot see from the log4net documentation why this should fail. What am I
doing wrong?

TIA

--
View this message in context: http://apache-logging.6191.n7.nabble.com/Multiple-processes-logging-to-single-file-unexplained-error-message-tp42667.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

George Mauer | 4 Dec 21:16 2013
Picon

Re: How to dynamically query and set logger levels?


I would like to create an area in my application that will let sysadmins modify logger levels directly.

This stackoverflow answer from 2009 implies that I can do it with

foreach (ILog logger in log4net.LogManager.GetCurrentLoggers()) { ((log4net.Repository.Hierarchy.Logger)logger).Level = log4net.Core.Level.Error; }

My application uses log4net 2.0.3 (1.2.13) and this seems to not be available as no implementation of ILog inherits that class. 

Instead I can grab each ILog's instances of ILogger to give me the name but will not let me query or set the Level. There is nothing I can cast this to in the meantime as it seems to be implemented by an internal class.

PS. How exactly does the email confirmation protect me from someone subscribing falsely? I subscribed by emailing from this address!
Stefan Bodewig | 21 Nov 15:05 2013
Picon

[ANN] Apache log4net 1.2.13 Released


The Apache log4net team is pleased to announce the release of Apache
log4net 1.2.13.  The release is available for download at

        http://logging.apache.org/log4net/download.html

The Apache log4net library is a tool to help the programmer output log
statements to a variety of output targets.  log4net is a port of the
excellent Apache log4j framework to the Microsoft(R) .NET runtime.

The log4net 1.2.13 release fixes a problem with stack frames of dynamic
methods in .NET 4.0 as well as a few regressions introduced with 1.2.12.
The assemblies built for .NET 3.5 (CP) now also contain the ILog
extensions methods.

See the release-notes at

    http://logging.apache.org/log4net/release/release-notes.html

for a full list of changes.

Please verify signatures using the KEYS file available at the above
location when downloading the release.

For complete information on log4net, including instructions on how to
submit bug reports, patches, or suggestions for improvement, see the
Apache log4net website:

http://logging.apache.org/log4net/

Stefan Bodewig on behalf of the log4net community
Douglas Neary | 13 Nov 21:57 2013

log4net 1.2.12, rolling file appender quits logging after some time

All:

First time poster, long time user.   Thanks for a great tool.

The background:
I have log4net version 1.2.12 of log4net running on Windows Server 2008 R2.  This is an Asp.net application (.Net 3.5.1) with 3 separate web sites logging to 3 separate log files using the rolling file appender.    Log4net internal logging enabled for all 3 sites and directed to separate files.  I can post that output, but I did not as it is very verbose.

I was having a similar problem with log4net 1.2.10, I just updated to 1.2.12.

The good news:
Logging works fine for all 3 sites, for a while. 

The problem:
2 of the 3 logs quit writing after a while (hours, maybe a day or so max).  In the log4net internal logs, I see the following text written over and over (looks to be every time logging is attempted)
log4net: Opening file for writing [c:\logs\logfile2.log] append [False] or
log4net: Opening file for writing [c:\logs\logfile3.log] append [False]
The questions:
Can I get a timestamp emitted (or any other formatting) with log4net internal debugging?
Any idea how to track down root cause on why these 2 loggers quit logging after a while?

The web.config:
Snip of log4net from web.config from 1 site below.  The other 2 sites are identical except for the log file name.

  <log4net>
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
      <layout type="log4net.Layout.PatternLayout">
        <param name="ConversionPattern" value="%d [%t] %-5p %c [%x] - %m%n"/>
      </layout>
    </appender>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <param name="File" value="c:\logs\logfile1.log"/>
      <param name="AppendToFile" value="true"/>
      <param name="MaxSizeRollBackups" value="10"/>
      <param name="MaximumFileSize" value="100MB"/>
      <param name="RollingStyle" value="Size"/>
      <param name="StaticLogFileName" value="true"/>
      <layout type="log4net.Layout.PatternLayout">
        <!-- do not alter ConversionPattern, it is used for reporting.-->
        <param name="ConversionPattern" value="%date{yyyy-MM-dd HH:mm:ss.fff} [%t] [%x] %p %c - %m%n"/>
      </layout>
    </appender>
    <root>
      <level value="Info"/>
      <appender-ref ref="RollingLogFileAppender"/>
      <appender-ref ref="ConsoleAppender"/>
    </root>
  </log4net>

Thanks in advance for any guidance.

Doug

Picon

Exception when running a programatically configured RemoteAppender

Hi all,

I'm trying to programatically configure an RemoteAppender on the client
side, but I end up in an exception (see below). Apparently the callback
is not set, and looking through the source code for log4net I cannot
find any obvious reason for the callback to not be set.

I have the setup running by configuring the RemoteAppender from a config
file, but I need to set the logging server based on information given at
runtime.
The code I used to try and achieve my goal is inserted below.

Thank you for any help or hints.

/Mikael

===== Exception begin =====
log4net:ERROR [RemotingAppender] ErrorCode: GenericFailure. Failed in
SendBufferCallback
System.Runtime.Remoting.RemotingException: Server encountered an
internal error. For more information, turn off customErrors in the
server's .config file.

Server stack trace:

Exception rethrown at [0]:
    at
System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage
reqMsg, IMessage retMsg)
    at
System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&
msgData, Int32 type)
    at
log4net.Appender.RemotingAppender.IRemoteLoggingSink.LogEvents(LoggingEvent[]
events)
    at log4net.Appender.RemotingAppender.SendBufferCallback(Object state)
===== Exception end =====

===== Server.vb begin =====
'Make log4net look for logging.config
<Assembly: log4net.Config.XmlConfigurator(ConfigFile:="logging.config",
Watch:=True)>

Namespace My
   Partial Friend Class MyApplication
     Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e
As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles
Me.Startup
       'Start the logging service
       StartLogging()
     End Sub

Private Sub StartLogging()
       Trace.WriteLine("Starting logging server...", "Info")

       Try
         'Configure remoting. This loads the TCP channel as specified in
the .config file.
System.Runtime.Remoting.RemotingConfiguration.Configure("logging.config", False)
'Using logging.config as configuration file

         'Publish the remote logging server. This is done using the
log4net plugin.
         log4net.LogManager.GetRepository().PluginMap.Add(New
log4net.Plugin.RemoteLoggingServerPlugin("LoggingSink"))
       Catch ex As Exception
         Trace.WriteLine("Exception: " + ex.Message, "Error")
       End Try
     End Sub
   End Class
===== Server.vb end =====

===== logging.config begin (server) =====
<?xml version="1.0"?>
<configuration>
   <configSections>
     <section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
   </configSections>

   <appSettings>
     <add key="log4net.Config" value="logging.config" />
     <add key="log4net.Config.Watch" value="True" />
     <!--<add key="log4net.Internal.Debug" value="true"/>-->
   </appSettings>

   <log4net>
     <appender name="FileAppender"
type="log4net.Appender.RollingFileAppender">
       <file value="C:\logs\TunstallLogs.txt" />
       <appendToFile value="true" />
       <rollingStyle value="Size"/>
       <maxSizeRollBackups value="20"/>
       <maximumFileSize value="100MB"/>
       <countDirection value="-1"/>
       <layout type="log4net.Layout.PatternLayout">
         <conversionPattern value="%date [%thread] %-5level %logger
(%property{log4net:HostName}) [%ndc] - %message%newline" />
       </layout>
     </appender>

     <root>
       <level value="VERBOSE" />
       <appender-ref ref="FileAppender" />
     </root>
   </log4net>
   <system.runtime.remoting>
     <application name="Log4netRemotingServer">
       <!-- We need to define the remoting channels on which we will publish
            the remote logging sink. -->
       <channels>
         <channel displayName="Server Channel" ref="tcp server"
port="8085"/>
       </channels>
     </application>
   </system.runtime.remoting>
</configuration>
===== logging.config end (server) =====

===== Client.vb begin =====
Namespace My
   Partial Friend Class MyApplication
     Public Shared Tlog As log4net.ILog

     Private Sub ConfigureLog()
       Dim root As log4net.Repository.Hierarchy.Logger
       root = CType(LogManager.GetRepository(), Hierarchy).Root
       root.AddAppender(FileAppender())
       root.AddAppender(RemoteAppender())
       root.Repository.Configured = True
     End Sub

     Private Function FileAppender() As IAppender
       Dim localFileAppender As log4net.Appender.FileAppender = New
FileAppender()
       localFileAppender.Name = "file"
       localFileAppender.AppendToFile = True
       localFileAppender.File = "C:\logs\filelog.txt"
       localFileAppender.Layout = New
log4net.Layout.PatternLayout("%date{dd-MM-yyyy HH:mm:ss,fff} %5level
[%2thread] %message (%logger{1}:%line)%n")
       localFileAppender.Threshold = log4net.Core.Level.All
       localFileAppender.ActivateOptions()

       Return localFileAppender
     End Function

     Private Function RemoteAppender() As IAppender
       Dim localRemoteAppender As log4net.Appender.RemotingAppender =
New RemotingAppender()
       localRemoteAppender.BufferSize = 95
       localRemoteAppender.Layout = New
log4net.Layout.PatternLayout("%date{dd-MM-yyyy HH:mm:ss,fff} %5level
[%2thread] %message (%logger{1}:%line)%n")
       localRemoteAppender.Fix = log4net.Core.FixFlags.Domain
       localRemoteAppender.Lossy = False
       localRemoteAppender.Name = "Remote"
       localRemoteAppender.Threshold = log4net.Core.Level.All
       localRemoteAppender.OnlyFixPartialEventData = True
       'localRemoteAppender.Sink = "tcp://" +
My.Settings.CT_PrimaryServerIP + ":8085/LoggingSink"
       localRemoteAppender.Sink = "tcp://192.168.10.11:8085/LoggingSink"
       localRemoteAppender.ActivateOptions()

       Return localRemoteAppender
     End Function

     Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e
As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles
Me.Startup

       ConfigureLog()
       Tlog =
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.ToString
+ " [Default instance]")

       Tlog.Info("Some info...")

       'Some more work done here.....
     End Sub

===== Client.vb end =====


Gmane