Calin Pavel | 17 Oct 11:55 2014
Picon

All threads blocked while logging

Hello everybody,

I do have an .NET application (Windows Service) that collects data from a lot of sources (DBs, log files, machines event logs, ...) and uses Log4Net to log details of the actions / execution.  As expected, I'm using a high number of threads to collect data, threads that are writing logs in some files (RollingFileAppenderer).

Lately it happens that the entire application is BLOCKED because all threads were trying to acquire a read lock, like in the stack trace:
000000001ac3d998 00000000774715fa [HelperMethodFrame: 000000001ac3d998] System.Threading.Thread.SleepInternal(Int32)
000000001ac3da90 000007fef747b5e9 System.Threading.Thread.Sleep(Int32)
000000001ac3dac0 000007fef5fb9631 System.Threading.ReaderWriterLockSlim.EnterMyLockSpin()
000000001ac3db90 000007fef5cd297e System.Threading.ReaderWriterLockSlim.TryEnterReadLockCore(TimeoutTracker)
000000001ac3dbf0 000007fef5cd28fa System.Threading.ReaderWriterLockSlim.TryEnterReadLock(TimeoutTracker)
000000001ac3dc40 000007fe98fb4efd log4net.Repository.Hierarchy.Logger.CallAppenders(log4net.Core.LoggingEvent)
000000001ac3dcc0 000007fe98fb4907 log4net.Repository.Hierarchy.Logger.Log(System.Type, log4net.Core.Level, System.Object, System.Exception)
000000001ac3dd30 000007fe98fb47f9 log4net.Core.LogImpl.Info(System.Object) 
....

Did you encountered this before or did anybody else reported similar problems?

May be it's important to mention:
- I'm using Log4Net 1.2.13, .NET 4.5 on Windows 2008 R2
- that my threads have a timeout, and if they do not finish the job in the given interval they are aborted.

In relation with this, I found a possible explanation of application hanging here: http://chabster.blogspot.ro/2013/07/a-story-of-orphaned-readerwriterlockslim.html

Could it be that the acquire of read lock in Logger.CallAppenderers method to generate our problems?

Thank you in advance,
Calin Pavel
Rob Richardson | 3 Oct 22:45 2014

Two logs have the same appenders

I want to get two independent sets of appender objects from the same configuration file, so that I can use
different file names in a FileAppender, for example.  But the standard way of getting appender objects is
to use the LogManager object, which is static.  Since there's only one LogManager, it will always return
the same set of appender objects.  So, I get one ILog object, get its FileAppender object, set its file name,
and write a message, and it appears in the expected file.  Then, I get another ILog object, get the
FileAppender object,  set its file name to some other file, and write a message, and that message appears in
the second file.  Finally, I go back to the first file appender, write another message, and it appears in the
second appenders file.  

Is there a way to copy a FileAppender object, or to get a new object for the same appender name out of the LogManager?

Thanks very much!

RobR, who will probably have to just build the logger programmatically instead of using a configuration file
Steve Hueners | 18 Aug 22:07 2014
Picon

AdoNetAppender on Azure SQL: Works then quits working

Last week I stepped thru the hoops required to configure a connection
string for my Azure SQL  db and confirmed that logging was working as
expected. Log messages were stored for several days, but at some
point, the logging ceased. I re-published the site (without changing
anything related to Log4Net) and logging was again active. Any other
similar reports? Anything non-optimal with my config?

much appreciated!

    <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
      <bufferSize value="1" />
      <connectionType value="System.Data.SqlClient.SqlConnection,
System.Data,  Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089" />

      <connectionString
value="Server=tcp:myServer.database.windows.net,1433;Database=myDatabase;User
ID=myUser;Password=myPassword;Trusted_Connection=False;Encrypt=True;Connection
Timeout=30;" />
      <commandText value="INSERT INTO CULog
([Date],[Level],[Message],[Exception], Logger) VALUES ( <at> log_date,
 <at> log_level,  <at> message,  <at> exception,  <at> logger)" />
      <parameter>
        <parameterName value=" <at> log_date" />
        <dbType value="DateTime" />
        <layout type="log4net.Layout.RawTimeStampLayout" />
      </parameter>
      <parameter>
        <parameterName value=" <at> log_level" />
        <dbType value="String" />
        <size value="50" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%level" />
        </layout>
      </parameter>
      <parameter>
        <parameterName value=" <at> message" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%message" />
        </layout>
      </parameter>

      <parameter>
        <parameterName value=" <at> exception" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.ExceptionLayout" />
      </parameter>
      <parameter>
        <parameterName value=" <at> logger" />
        <dbType value="String" />
        <size value="4000" />
        <layout type="log4net.Layout.PatternLayout">
          <conversionPattern value="%logger" />
        </layout>
      </parameter>

Ananth Tatachar | 14 Aug 17:51 2014
Picon

Inconsistent results observed while using BufferingForwardAppender

I am working with log4net version : 1.2.12.0 .

 

I am getting inconsistent results , while using RollingFileAppender with BufferingForwardAppender.

My application is a multithreaded application. I spawned 5 threads Each will call the constructor of MyClass and SomeFunction once.

My application's sertup is as follows:

 

Web.config:

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

 <appender name="RollingLocalFileAppender" type="log4net.Appender.RollingFileAppender">
      <
file type="log4net.Util.PatternString" value="C:\Logs\TFile.log" />
      <
rollingStyle value="Date" />
     <
datePattern value="yyyy-MM-dd" />
     <
maxSizeRollBackups value="10" />
      <
appendToFile value="true" />
     <
layout type="log4net.Layout.PatternLayout">
        <
conversionPattern value="%level %date{yyyy-MM-dd'T'HH:mm:ss.fffzzz} %property{hostname}  %property{guid} %message%newline" />
     </
layout>
    </
appender>
    <
appender name="BufferedFileAppender" type="log4net.Appender.BufferingForwardingAppender">
      <
bufferSize value="512" />
     <
evaluator type="log4net.Core.TimeEvaluator">

        <interval value="10" />
       
<!--Send buffered events immediately if 10 seconds pass-->
      </
evaluator>
     
<Fix value="0" />
    
<!--Buffering can have severe performance degradation if this is set to the default (ALL)-->
    </
appender>

 

 

Logging Class:

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

 

Class MyClass

{

public MyClass()

{

Log4net.ThreadContext.Properties["guid"] = Guid.NewGuid();

}

 

public void SomeFunction()

{

Ilog log = LogManager.GetLogger(typeof(MyClass));

Log.Info("my message");

}

 

}

 

 

Tfile.log(Result)

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

Observed Results:

 

INFO 2014-08-14T10:47:36.659-04:00 ANANTHTATACHAR MyAudsDigest [LQR-Y8c71EmtWl7ZqItYoQ] my message

INFO 2014-08-14T10:47:36.659-04:00  ANANTHTATACHAR MyAudsDigest  [9hDzS-_Su0SrEoXZF_aGMw] my message

INFO 2014-08-14T10:47:36.729-04:00 ANANTHTATACHAR MyAudsDigest  [GsxT7aTfNEq1uIsqPYeZ5w]  my message

INFO 2014-08-14T10:47:36.789-04:00 ANANTHTATACHAR MyAudsDigest [9hDzS-_Su0SrEoXZF_aGMw] my message

INFO 2014-08-14T10:47:36.955-04:00 ANANTHTATACHAR MyAudsDigest  [9hDzS-_Su0SrEoXZF_aGMw] my message

 

 

 

Expected Results:

Unique guid in all the messages.

 

 

 

 

 

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

 

I understand that Fix value  NONE in log4net.Appender.BufferingForwardingAppender will not fix any volatile variables , but making it all results in all my guids in all the 5 messages becoming same.

 

Could anybody please tell me how to fix this issue?

Mohkam Singh Sawhney | 14 Aug 12:31 2014
Picon

RollingFileAppender overwriting previous log files on application restart

Hi,

I am using log4Net v1.2.13 in a .NET 4 C# project. I have setup a RollingFileAppender to roll on size. My aim is to keep appending to a log file and roll on size. I need to maintain all the previous log files. But I found that every time my application restarts all the log files after the 2nd log file that was generated in the previous run get overwritten.

For testing purposes I set the rollover size to 3KB. Below is the appender configuration.

<appender name="RollingAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs22\myFile_d.log" />
<appendToFile value="true" />
<rollingStyle value="size" />
<staticLogFileName value="false" />
<maximumFileSize value="3KB" />
<countDirection value="1" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value = "%date %-5level [%logger] %message%newline%exception"/>
</layout>
</appender>

On first run of my application the appender rolls the log files on size. It created 3 log files myFile_d.log.0, myFile_d, myFile_d.log.2.  Each log file was around 5KB before getting rolled.

When I ran the application again, this time instead of creating a new log file myFile_d.log.3, Log4Net started overwriting the second log file that was generated earlier (that is myFile_d.log.1 was overwritten). It then proceeded to overwrite myFile_d.log.2.

I updated the config and included <maxSizeRollBackups value="-1" />. This time log files were rolled without any overwriting of existing files.

A similar scenario described in this issue tracker - LOG4NET-378. The bug has been closed with resolution fixed in v1.2.12.

I would appreciate it if somebody could confirm the following points
1. What is the default value of maxSizeRollBackups if it is not mentioned in the config file. I could not find this in documentation for this property.

2. For the scenario that I described is expected to include maxSizeRollBackups=-1 in the config file?



Thanks and Regards,

Mohkam Singh


Venkatasamy, Vanitha | 7 Aug 18:43 2014

Section or group name 'log4net' is already defined

I have a parent and child application. Log4net has been declared in both the web.config’s

 

Suddenly I started getting this below error in child application.

 

Exception information:

    Exception type: ConfigurationErrorsException

    Exception message: Section or group name 'log4net' is already defined. Updates to this may only occur at the configuration level where it is defined. (\web.config line 5)

 

 

If I remove the section from child web.config, some other error .

 

Any suggestion to look for

 

Thanks,

Vanitha Venkatasamy

XPAND Corporation.

 

 

 

This message contains Devin Group confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail in error and delete this e-mail from your system. E-mail transmissions cannot be guaranteed secure, error-free and information could be intercepted, corrupted, lost, destroyed, arrive late, incomplete, or contain viruses. The sender therefore does not accept liability for errors or omissions in the contents of this message which may arise as result of transmission. If verification is required please request hard-copy version
Shing Hing Man | 2 Aug 19:09 2014
Picon

How to specify a log output folder in RollingFileAppender

Hi,
  I am trying to set up llog4net  to use RollingFileAppender in  F# in VS 2013.

 <appender name="Roll" type="log4net.Appender.RollingFileAppender">
      <file      value="log_"/>
      <appendToFile value="true"/>
      <rollingStyle value="Date"/>
      <staticLogFileName value="false" />
      <datePattern value="yyyy_MM_dd.'txt'"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger - %m%n" />
      </layout>
    </appender>

The above works. The log file log_2014_08_02.txt ends up  in {project}/bin/Debug directory.

However, I would like the log file to be in c:\ ,say.
I have tried
    <file      value="c:\log_"/>
and
  <file      value="${HOMEDRIVE}\log_"/>
but none of the above works.

How to set up <file> so that the output directory is in c:\  ?
Thanks in advance for your assistance!

Shing







Ananth Tatachar | 24 Jul 02:31 2014
Picon

Fwd: Log4net.ThreadContext.Properties Having stale data. How to resolve it?



---------- Forwarded message ----------
From: Ananth Tatachar <ananth.tatachar <at> gmail.com>
Date: Wed, Jul 23, 2014 at 8:24 PM
Subject: Log4net.ThreadContext.Properties Having stale data. How to resolve it?
To: log4net-user <at> logging.apache.org


I am using a RollingFileAppender , and my own custom layout. My application is multithreaded. Each thread will generate unique random data and is supposed to log it using log4net framework. However if I create multiple threads in quick succession I notice stale data in my logs , this goes away if each thread sleeps for 50 ms before logging. I am not able to figure out a solution to this issue or find its cause please do help me.

My logging function looks like this:


    log4net.ThreadContext.properties["randomGeneratedData"] = randomGeneratedData;
    private ILog myLog = 
           LogManager.GetLogger(typeof(LogTest));
    using (log4net.NDC.Push("ndcTest1"))
    {
        using (log4net.NDC.Push("ndcTest2"))
            {
                myLog.Info("myLogTest");
            }
    }





Result of logging:

       NDC = "ndcTest1 ndcTest2" , randomGeneratedData = rad1
       NDC = "ndcTest1 ndcTest2" , randomGeneratedData = rad2
       NDC = "", randomGeneratedData = rad2 

and so on ...


I tried to clear log4net.ThreadContext.Properties before filling it again , but it was of no use. Please help. 

Ananth Tatachar | 24 Jul 02:30 2014
Picon

Fwd: Log4net.ThreadContext.Properties Having stale data. How to resolve it?



---------- Forwarded message ----------
From: Ananth Tatachar <ananth.tatachar <at> gmail.com>
Date: Wed, Jul 23, 2014 at 8:24 PM
Subject: Log4net.ThreadContext.Properties Having stale data. How to resolve it?
To: log4net-user <at> logging.apache.org


I am using a RollingFileAppender , and my own custom layout. My application is multithreaded. Each thread will generate unique random data and is supposed to log it using log4net framework. However if I create multiple threads in quick succession I notice stale data in my logs , this goes away if each thread sleeps for 50 ms before logging. I am not able to figure out a solution to this issue or find its cause please do help me.

My logging function looks like this:


    log4net.ThreadContext.properties["randomGeneratedData"] = randomGeneratedData;
    private ILog myLog = 
           LogManager.GetLogger(typeof(LogTest));
    using (log4net.NDC.Push("ndcTest1"))
    {
        using (log4net.NDC.Push("ndcTest2"))
            {
                myLog.Info("myLogTest");
            }
    }





Result of logging:

       NDC = "ndcTest1 ndcTest2" , randomGeneratedData = rad1
       NDC = "ndcTest1 ndcTest2" , randomGeneratedData = rad2
       NDC = "", randomGeneratedData = rad2 

and so on ...


I tried to clear log4net.ThreadContext.Properties before filling it again , but it was of no use. Please help. 

Brian Broughton | 2 Jul 17:24 2014
Picon

AdoNetAppender - Wrong Values in Some Columns

Hello,

I have configured an AdoNetAppender in code (see below). I do end up with a 
record inserted into the table. The values inserted into the Date, Message 
and Exception columns are correct. However, the Thread, Level and Logger 
columns all contain the contents of "%message. If I use any of the other 
appenders (such as FileAppender), all values are logged correctly.

I’ve been searching for a couple of hours now and cannot find where anyone 
else has had this issue. Any help would be appreciated!

var dbAppender = new AdoNetAppender
            {
                Layout = layout,
                BufferSize = 1,
                ConnectionType = "System.Data.SqlClient.SqlConnection, 
System.Data, Version=1.0.3300.0, Culture=neutral, 
PublicKeyToken=b77a5c561934e089",
               ConnectionString = string.Format("data source='{0}';initial 
catalog={1};integrated security=false;persist security info=True;User ID=
{2};Password={3}", dbConfig.ServerName, dbConfig.DatabaseName, 
dbConfig.UserId, dbConfig.Password),
                CommandText = "INSERT INTO Log ([Date],[Thread],[Level],
[Logger],[Message],[Exception]) VALUES ( <at> log_date,  <at> thread,  <at> log_level, 
 <at> logger,  <at> message,  <at> exception)"          
            };

            dbAppender.AddParameter(new AdoNetAppenderParameter { 
ParameterName = " <at> log_date", DbType = DbType.DateTime, Layout = new 
RawTimeStampLayout() });
            dbAppender.AddParameter(new AdoNetAppenderParameter { 
ParameterName = " <at> thread", DbType = DbType.String, Size = 255, Layout = new 
Layout2RawLayoutAdapter(new PatternLayout { ConversionPattern = "%thread" }) 
});
            dbAppender.AddParameter(new AdoNetAppenderParameter { 
ParameterName = " <at> log_level", DbType = DbType.String, Size = 50, Layout = 
new Layout2RawLayoutAdapter(new PatternLayout { ConversionPattern = "%level" 
}) });
            dbAppender.AddParameter(new AdoNetAppenderParameter { 
ParameterName = " <at> logger", DbType = DbType.String, Size = 255, Layout = new 
Layout2RawLayoutAdapter(new PatternLayout { ConversionPattern = "%logger" }) 
});
            dbAppender.AddParameter(new AdoNetAppenderParameter { 
ParameterName = " <at> message", DbType = DbType.String, Size = 4000, Layout = 
new Layout2RawLayoutAdapter(new PatternLayout { ConversionPattern = 
"%message" }) });
            dbAppender.AddParameter(new AdoNetAppenderParameter { 
ParameterName = " <at> exception", DbType = DbType.String, Size = 2000, Layout = 
new Layout2RawLayoutAdapter(new ExceptionLayout()) });

            dbAppender.ActivateOptions();

Thank you,
Brian

Rob Richardson | 27 Jun 14:25 2014

Writing to two different log files

Greetings!

 

I am attempting to write to two different log files from inside one C# application.  I have defined two rolling file appenders.  I use the GetLogger() function to get references to each one, and I write to each in turn.  But both messages end up in the first file (cranesimulator_console.log), and the second file (cranesimulator_console_sim.log) is never created.

 

Here is my configuration file:

 

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

<log4net>

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

    <file value="CraneSimulator_Console.log" />

    <appendToFile value="true" />

    <maxSizeRollBackups value="90" />

    <rollingStyle value="Size" />

 

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

      <conversionPattern value="%date - %message%newline" />

    </layout>

  </appender>

 

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

    <file value="CraneSimulator_Console_sim.log" />

    <appendToFile value="true" />

    <maxSizeRollBackups value="90" />

    <rollingStyle value="Size" />

 

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

      <conversionPattern value="%date - %message%newline" />

    </layout>

  </appender>

</appender>

  <root>

     <level value="DEBUG" />

     <appender-ref ref="RollingFile" />

     <appender-ref ref="RollingFile_sim" />

  </root>

 

</log4net>

 

And here is the code that should be writing to the files:

 

            public CraneSimulator_Console(string xmlFileName)

            {

                  // m_simulator = new Simulator(xmlFileName, m_logger);

                  // string fullType = m_simulator.Database.GetType().AssemblyQualifiedName;

                  ILog m_logger = LogManager.GetLogger("RollingFile");

                  ILog simLogger = LogManager.GetLogger("RollingFile_sim");

                  System.IO.FileInfo logConfigFile = new System.IO.FileInfo(Environment.CurrentDirectory +

                                                                    "multiple_files.xml");

                  XmlConfigurator.ConfigureAndWatch(logConfigFile);

                  m_logger.Info("This is from cranesimulator_console.");

 

                  simLogger.Info("This should be in the sim logger.");

            }

 

Many thanks for your help!

 


Gmane