Michel Émond | 8 Jun 15:43 2015

Rolling log file is overwritten when application is restarted

Hello,

This is the first time I contribute to an open source project, your assistance will be much appreciated.
I read your FAQ and I believe I'm doing things in the right manner. Please let me know otherwise.

While using version 1.2.13, I'm experiencing the issue described in this bug:
https://issues.apache.org/jira/browse/LOG4NET-378

In short, my app is running, rolling style is set to Composite, log files are piling up in the folder, all is good. Then I reset IIS, and restart my app. I would expect the rolling to continue on or after the last file. But instead, the rolling restarts at index 1 and overwrites the existing files.

The original bug fix addresses the issue in the InitializeFromOneFile() method.
However, the GetWildcardPatternForFile() method also needs the baseFileName to be adjusted with the datePattern so the proper files are searched.
I placed a file path fix in the DetermineCurSizeRollBackups() method, so it's then passed down to the two other methods and everyone gets happy.

Here's a calling stack sample:
DetermineCurSizeRollBackups()
|
+--GetExistingFiles()
|  +--GetWildcardPatternForFile()
|
+--InitializeRollBackups()
   +--InitializeFromOneFile()


You'll find attached to this email:
- the part of my web.config file that relates to log4net
- a patch containing my fix

Please let me know how good this fix is, and if it fits your quality standards.
Once we're settled, I could work on the unit tests, or let you deal with it at your convenience.

Thanks!

--
<at> import url(<a class="moz-txt-link-freetext" href="http://fonts.googleapis.com/css?family=Roboto+Slab:400,300,700">http://fonts.googleapis.com/css?family=Roboto+Slab:400,300,700); a, a:link, a:visited { color:#000000; }

Michel Émond
Programmer Analyst

T  1-514-272-0979 #240
T  1-800-972-0979 #240
www.innobec.com

Attachment (config.xml): text/xml, 1603 bytes
--- log4net-1.2.13\src\Appender\RollingFileAppender.cs	Sun Nov 17 14:44:38 2013 UTC
+++ log4net-1.2.13-fix\src\Appender\RollingFileAppender.cs	Tue May 12 17:53:22 2015 UTC
 <at>  <at>  -718,6 +718,10  <at>  <at> 
 			using(SecurityContext.Impersonate(this))
 			{
 				fullPath = System.IO.Path.GetFullPath(m_baseFileName);
+				if (m_rollDate && !m_staticLogFileName)
+				{
+					fullPath = CombinePath(fullPath, m_now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo));
+				}
 				fileName = System.IO.Path.GetFileName(fullPath);
 			}
 
 <at>  <at>  -901,19 +905,6  <at>  <at> 
 			}
             */
 	
-			// Only look for files in the current roll point
-			if (m_rollDate && !m_staticLogFileName)
-			{
-				string date = m_dateTime.Now.ToString(m_datePattern, System.Globalization.DateTimeFormatInfo.InvariantInfo);
-				string prefix = m_preserveLogFileNameExtension ?
Path.GetFileNameWithoutExtension(baseFile) + date : baseFile + date;
-				string suffix = m_preserveLogFileNameExtension ? Path.GetExtension(baseFile) : "";
-				if (!curFileName.StartsWith(prefix) || !curFileName.EndsWith(suffix))
-				{
-					LogLog.Debug(declaringType, "Ignoring file ["+curFileName+"] because it is from a different
date period");
-					return;
-				}
-			}
-            
 			try 
 			{
 				// Bump the counter up to the highest count seen so far
karlkras | 9 Apr 19:17 2015
Picon

Can't get RollingFileAppender to work...

Hello again. So I'm trying to configure a RollingFileAppender logger to work
against a custom level. However, when I call the custom level no file with
content is created/produced.
The xml configuration looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
	<configSections>
		<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"
requirePermission="false" />
	</configSections>
	<log4net debug="True">
		<level>
			<name value="AUDIT" />
			<value value="80000" />
		</level>
		<root>
			<appender-ref ref="LogglyLogger" >
				<threshold value="DEBUG" />
			</appender-ref>
		</root>
		<logger name="EventLogger" additivity="False">
			<level value="ERROR"/>
		</logger>
		<logger name="RollingFile" additivity="False">
			<level value="AUDIT"/>
		</logger>
		
		<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
			<file value="c:\logs\connector\Connector.log" />
			<appendToFile value="true" />
			<datePattern value="yyyyMMdd" />
			<rollingStyle value="Date" />
			<maxSizeRollBackups value="30"/>
			<staticLogFileName value="true" />
			<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
			<layout type="log4net.Layout.PatternLayout">
				<conversionPattern value="%-5p %d [%thread] %5rms %-22.22c{1} %-18.18M -
%m%n" />
			</layout>
		</appender>

...

the C# code looks like this:

public class MyLogger
{
		static readonly log4net.Core.Level auditLevel = new
log4net.Core.Level(80000, "Audit");
                private static ILog _logger;

                public void MyLogger()
                {
			string logFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"Config\\Logging.config");
			FileInfo finfo = new FileInfo(logFilePath);
			log4net.Core.Level auditLevel = new log4net.Core.Level(80000, "Audit");
			log4net.LogManager.GetRepository().LevelMap.Add(auditLevel);
			log4net.Config.XmlConfigurator.ConfigureAndWatch(finfo);
			_logger = LogManager.GetLogger(typeof(WAConnectorLogger));
                }

		public void Audit(string message)
		{
		
_logger.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType,
				auditLevel, message, null);
		}

but when I call this method, no log is produced. Any ideas what I'm doing
wrong here?
It all appears to proceed without error so I'm assuming something in my
configuration isn't quite right.
Other appenders are working as hoped, so there's no problem loading the
log4net xml file.

thanks!

--
View this message in context: http://apache-logging.6191.n7.nabble.com/Can-t-get-RollingFileAppender-to-work-tp54533.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

karlkras | 8 Apr 01:13 2015
Picon

How to use a custom level in logger interface...

So I've found a sample that states to add a custom level to the log4net xml
configuration as such:
	<log4net>
	    <level>
	        <name value="AUDIT" />
		<value value="80000" />
	    </level>

and I'm guessing I can define my logger to use it like this:

...
		<logger name="RollingFile" additivity="False">
			<level value="AUDIT"/>
		</logger>

in in the C# code, how do I specify to call the logger to call the logger
with the "AUDIT" level? e.g., for an Error level message I perform an
log4net.ILog.Error(...) call.

what do I do for the custom level since this support isn't built in, i.e.,
how/where do I inject the handlers for interact with the log4net process?

thanks...

--
View this message in context: http://apache-logging.6191.n7.nabble.com/How-to-use-a-custom-level-in-logger-interface-tp54520.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

DeveloperM | 7 Apr 15:44 2015

Logging works in VS but not when deployed

(Apologizing for cross-posting...)

I am working in a Dynamics CRM 2011on-premises C# .Net environment. This is
the first time I have used log4net so bear with me, please...

My app.config entry for log4net is:
<log4net>
<appender name="RollingFileAppender"
type="log4net.Appender.RollingFileAppender">
  <file value="EDI File Generator Log.txt" />
  <appendToFile value="true" />
  <rollingStyle value="Size" />
  <maxSizeRollBackups value="10" />
  <maximumFileSize value="20MB" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <conversionPattern value="%date [%thread] %level %logger -
%message%newline" />
  </layout>
</appender>
<root>
  <level value="INFO"/>
  <appender-ref ref="RollingFileAppender"/>

</root>

In the program I have coded:
private static readonly ILog log =
LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

And throughout the program there are several places I call a method which
executes:
log.Info(sMessage);

When I execute the code from VS 2010, the program runs and messages are
logged to the log file. When I deployed the program to my own machine, the
program runs but no log entries are written.

--
View this message in context: http://apache-logging.6191.n7.nabble.com/Logging-works-in-VS-but-not-when-deployed-tp54506.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Nicholas Dudas | 27 Mar 19:51 2015
Picon

Fwd: FileAppender ObjectDisposedException

I may have found a small bug in the file appender where the manual reset event is not cleaned up correctly during shutdown. 


--
Thanks,

Joseph L. Casale | 6 Mar 22:01 2015

Custom appender instantiation

I have a custom appender that uses parameters from the App.config file, however
I need to call an internal method after instantiation once the fields have been populated.

I see PreAppendCheck
Gert Kello | 5 Mar 13:01 2015
Picon

Debug info file for log4net release

Hi.

Is it possible to download the log4net.pdb file for log4net-1.2.13-bin-newkey.zip? So that debugging log4net would be possible without making custom build.


Is there some reason why it is not included in zip? Would You consider adding it to coming releases?

Gert

Gert Kello | 4 Mar 09:27 2015
Picon

AppenderSkeletion lock in DoAppend

Hi.

I'm trying to create a database appender which high throughput... I looked at code in AppenderSekeletion.DoAppend() method and saw following comment:

    public void DoAppend(LoggingEvent loggingEvent)
    {
      // This lock is absolutely critical for correct formatting
      // of the message in a multi-threaded environment.  Without
      // this, the message may be broken up into elements from
      // multiple thread contexts (like get the wrong thread ID).

      lock (this)
      {

I would like to remove this lock from my code but there's a couple of issues I do not understand:
1. As I do not know the internals of log4net well enough I do not understand why lock is important for message formatting? Is it because the Layout.Format is not supposed to be thread safe? Or is it because the same instance of m_renderWriter could be used by multiple threads (well, usage of m_renderWriter is protected by another lock, added later. But AFAIK the RenderLoggingEvent(LoggingEvent loggingEvent) is still not 100% thread safe)
2. The comment does not mention that lock is crucial for m_recursiveGuard to work correctly. That's my main complaint: I almost overlooked the issue of potentially skipped logging events.
3. What about implementations of IFilter.Decide? Are those (supposed to be) thread safe?

Gert
Thiemo.Kellner | 26 Feb 13:36 2015
Picon

64bit problem?

Hi all

 

I am at my wits’ end. We developped PowerShell script which uses log4net. I can run the script successfully from a batch file on my laptop but on the server I get

 

Attempting to perform the InitializeDefaultDrives operation on the 'FileSystem'

provider failed.

I:\WA_ANALYSE\AAA_INFA_CORE\Scripts\metadata_join_params-thiemo.ps1 :

Exception calling "LoadFile" with "1" argument(s): "The parameter is

incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"

At line:1 char:1

+ I:\WA_ANALYSE\AAA_INFA_CORE\Scripts\metadata_join_params-thiemo.ps1

-stat_activi ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~

    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorExcep

   tion

    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorExceptio

   n,metadata_join_params-thiemo.ps1

 

 

I found http://stackoverflow.com/questions/10249406/powershell-v2-load-a-com-interop-dll which points to a possible problem with mixing 32 dlls in 64 bit PowerShell. As my laptop is 32 and the server 64 bit, I was wondering if this might cause the problem. At least I could pin the line of code where the exception gets thrown: [void][Reflection.Assembly]::LoadFile($log4netDllPathString)

 

Has anyone an idea?

 

Liebe Grüsse/Cordialement/Cordialità

 

Thiemo Kellner

 

--

Office fédéral de la statistique
Espace de l'Europe 10
2010 Neuchâtel / Suisse

IT-AB

Tel     +41 32 71 36516

 

Christopher Landry | 12 Feb 21:00 2015

Dynamically change log levels confined to ThreadContext

I have a web app, and I’m trying to allow users to set the logging level via a query parameter. Got this working pretty easily.

 

The issue is that it doesn’t just change the logging level for that request, it’s changed for all requests that come in during the life cycle of that request – since I’m setting it back to the default level when the request is resolved.

 

I have tried adding the following in my appender, but it’s not working as I hoped.

 

<evaluator type=”log4net.spi.LevelEvaluator”>

     <threshold>

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

                <key value=”LogLevel” />

     </threshold>

</evaluator>

 

And set a ThreadContext property called LogLevel to the appropriate level, but that doesn’t seem to work either.

 

Any thoughts? Have I missed something obvious?

 

Thanks!

emacslisp | 9 Feb 02:53 2015
Picon

how to make log4net exclude Stack Trace

By default, log4net will log Stack Trace.

I create a wraper which inherit from "ILog" and implement "ILog" interface
directly.

public class MyLogger : ILog
{
    ...
    Error(object message, Exception exception)
    {
        log.Error(exception.Message);//Now it will show message only.
    }
    ...
}

then log4net.ILog log = new
MyLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

it could work.

However, I want to config log4net without logging stack trace.

but I could not find any useful information.

--
View this message in context: http://apache-logging.6191.n7.nabble.com/how-to-make-log4net-exclude-Stack-Trace-tp53708.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Gmane