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!

 

tirath.g | 12 Jun 05:59 2014
Picon

set buffersize conditionally?

hi,

is it possible to set buffersize conditionally. i am trying to use log4net
for entire orgnaziation solution and writing info to a database table. can i
set different values of buffer size programically depending on some
condition( like request coming from application 1 to use buffer size = 100
others to use 1). thankyou.

--
View this message in context: http://apache-logging.6191.n7.nabble.com/set-buffersize-conditionally-tp48117.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Alexey Polyakov | 1 Jun 16:49 2014

RE: log4net 1.2.13 performance issues (found the exact line that causes the problem)

Hello,

 

I have encountered a heavy drop in performance after migration from log4net 1.2.10 to 1.2.13. My research pointed out to the commit #1511303 and specifically to the line 1340:

                                             eventProperties[UserNameProperty] = UserName;

 

I attach the test harness I was using - without this line the logging is done in about 2 seconds, and after this line is added - it takes 24 seconds.

 

Can you please give any comment on what is going on? (is it safe to just remove this line and use patched version in production environment, or may be there is already a work in progress and a better solution)/

 

Best Regards,
Alexey Polyakov
Software Engineer


EPAM Systems
Ryazan office, Russia
GMT+3 (Standard) / GMT+3 (Daylight)

Office phone:       +7 (4912) 935-733, ext. 46229

Mobile phone:       +7 (910) 509-96-37

E-mail:         
        Alexey_Polyakov <at> epam.com

Skype:                 Aleksey__Polyakov (chat or call)

 

Attachment (smime.p7s): application/pkcs7-signature, 6197 bytes
Rob Richardson | 30 May 20:47 2014

AdoNetAppender not working PostgreSQL database using Npgsql

Greetings!

 

I am trying to get an AdoNetAppender to work, and I’m not succeeding.  For now, all I’m trying to do is to write a constant message to a database table.  Along with the AdoNetAppender, I have a RollingFileAppender that is working well.  I should get one record in my log table for every line in the log file.  I’m not getting anything.

 

This project is built in Microsoft Visual Studio 2008, and is running under Windows 7.  I am using the ConfigureAndWatch() method to set up my application’s logger. 

 

Here is the configuration file I’m using:

 

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

<log4net>

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

    <file value="CraneSimulator2.log" />

    <appendToFile value="true" />

    <maxSizeRollBackups value="90" />

    <rollingStyle value="Size" />

 

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

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

    </layout>

  </appender>

<appender name="NpgsqlAppender" type="log4net.Appender.AdoNetAppender">

    <bufferSize value="5" />

    <connectionType value="Npgsql.NpgsqlConnection, Npgsql, Version=2.0.11.91, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />

    <connectionString value="Server=127.0.0.1;Port=5434;Database=CraneSimulatorLog;User Id=xxxx;Password=yyyyyyyy;" />

    <commandText value="INSERT INTO Log (message) VALUES ('This is a log message')" />

</appender>

  <root>

     <level value="DEBUG" />

     <appender-ref ref="RollingFile" />

     <appender-ref ref="NpgsqlAppender" />

  </root>

 

</log4net>

 

Before this, I tried using ODBC, and that didn’t work either.

 

Can anyone tell me what’s wrong, or suggest a way in which I can see what error is happening?  There are no error messages in the PostgreSQL log files.

 

Thanks very much!

 

RobR

Tim Sirmovics | 27 May 02:48 2014
Picon

FW: RollingFileAppender overwriting file

I have been using the RollingFileAppender through numerous log4net version for about 3-4 years.

In the last few days I am now experiencing the following issue:

 

1.       Assume today is 27/05/2014

2.       Current log file is called Debug.log

3.       Log file builds up throughout the day.

4.       Next day (28/05/2014), log file Debug.log.27.log exists, last write time according to windows is 27/05/2014 11:59 pm

5.       Open log file, all entries from 27/05 are gone, log only contains a very small number of entries dated 28/05/2014 just after midnight.

 

I am now losing my logs for each day as they are being overwritten by the first few logs after midnight.

Only one process writes to this file.

The process is limited to only running a single instance at a time.

I have not changed my configuration for a long time, however I have included it below.

 

 

<!-- Last month, one file per day -->

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

    <file value="Logs\Debug.log" />

    <appendToFile value="true" />

    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />

    <rollingStyle value="Date" />

    <datePattern value=".dd'.log'" />

    <maxSizeRollBackups value="14" />

    <threshold value="DEBUG"/>

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

      <conversionPattern value="|%date| |%-5level| |%property{log4net:HostName}| |%logger{2}|: %message%newline" />

    </layout>

  </appender>

 

 

Is there any way I can prevent this from happening?


Tim Sirmovics
IT
tims <at> axima.com.au

 
AXIMA Pty. Ltd.
135 Boundary Road, Laverton North
Victoria 3026 Australia
T: +61 3 83685300
F: +61 3 83685333
W: www.axima.com.au

This message and any files transmitted with it are confidential and are intended solely for the use of those persons to whom the message is addressed. If you have received this message in error, please destroy and delete this message from your computer. Any unauthorised reproduction of this message or any files transmitted with it is strictly prohibited. All business is conducted pursuant to Axima's trading terms and conditions which may exclude or limit liability in certain circumstances.
codeMonkey | 2 May 16:01 2014
Picon

Rolling File Appender with a fixed extention

I would like my log files to have the following behaviour:

MyApp_2014-06-24.log          (this would be the current log file)
MyApp_1_2014-06-24.log       etc.
MyApp_2_2014-06-24.log
MyApp_3_2014-06-24.log   

I would like to keep the last 10 files, of the last 2 days, and the files
should be of maximum 15MB size.

Any help would be appreciated:)

Here is what I have so far:
    <appender name="RollingLogFileAppender"
type="log4net.Appender.RollingFileAppender">
      <file value="${APPDATA}\logs\MyApp"/>
      <appendToFile value="true"/>
      <rollingStyle value="Composite"/>
      <datePattern value=".yyyy-MM-dd'.log'"/>
      <maxSizeRollBackups value="10"/>
      <maximumFileSize value="15MB"/>
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date [%thread] %-5level %logger
[%property{NDC}] - %message%newline"/>
      </layout>
    </appender>

--
View this message in context: http://apache-logging.6191.n7.nabble.com/Rolling-File-Appender-with-a-fixed-extention-tp46662.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Hans Olausson | 30 Apr 16:32 2014

ECCN for log4net

 

Hi!

 

We need the ECCN (Export Control Classification Number) for log4net (related to export restrictions on our product that uses log4net). Has log4net got an ECCN?

 

This is related to encryption software and I think it is quite obvious  that log4net does not include any encryption but would be nice to refer to an ECCN classification for log4net when we classify our product.

 

Best regards,

 

Hans Olausson

 

Daniel Ingalla | 19 Apr 19:57 2014
Picon

Output in Ubuntu Linux

All,

Anyone have any experience logging on a .net mono app running on Ubuntu? I have a console appender setup on the root logger. This works on Windows without issue, but I see no output in Linux. My .Net app is started on the command line.

Probably a shell thing eh?

Regards,
D

Gmane