Ílson Bolzan | 26 Aug 19:18 2015
Picon

Problems with ThreadContext and TransactionScope

Has anyone tried to stack contexts and use Transaction scope at the same time?

I'm trying something like this:
using (log4net.ThreadContext.Stacks["contextLog"].Push("Saving Data")) { log.Info("Starting transaction"); using (var ts = new TransactionScope(TransactionScopeOption.Required)) { log.Info("Inside Transaction"); } }
and I'm getting that result:

2015/42/26 13:42:10,841 INFO  [Saving Data] Starting transaction
2015/42/26 13:42:10,870 INFO  [(null)] Inside Transaction

I was expecting it to have [Saving Data] instead of [(null)]  on the second line.

It appears to loose access to the log4net ThreadContext Stack as soon as it enters a transaction.

Do you know how to avoid this?

Thank you so much.


Jeremiah Gowdy | 18 Aug 19:21 2015

Log4net 1.2.14

My colleague Thomas Clegg and I are proposing to do a release of log4net numbered 1.2.14.  This release would
be the existing 1.2.13 release, plus the two patches for LOG4NET-455 and LOG4NET-462.  According to our
testing, this fixes log4net’s thread context for async/await usage.  By doing a bump of 1.2.13, we avoid
the large amount of unreleased changes pending in log4net 1.3.0.

I understand the two developers of log4net are not very available to assist with this release.  Once we’ve
prepared a diff for this release how do we proceed?
Ílson Bolzan | 17 Aug 22:54 2015
Picon

Log4net New Releases

Hi.

I was just wondering.
Given that there are commits from 8 days ago on the source repository.
Does anyone know hy the last stable release is from 2013?

Thanks,
Ílson Bolzan

--

Francois Botha | 7 Aug 14:00 2015
Picon

Log4Net Logging of two different levels to two different appenders for the same logger

Hi,

Please refer to the question and answer in http://stackoverflow.com/a/21188397/179494

I have a similar config (see below), but at the moment DEBUG statements (and above) also print in the console. My understanding is that with this config, only ERROR and above should print in the console, but all levels should print in the rolling file. What am I doing wrong?

My config:

  <log4net debug="false">
    <appender name="rollingFile" type="log4net.Appender.RollingFileAppender,log4net">
      <param name="File" value="logs\log.txt" />
      <param name="AppendToFile" value="false" />
      <param name="RollingStyle" value="Date" />
      <param name="DatePattern" value="yyyy.MM.dd" />
      <param name="StaticLogFileName" value="true" />
      <layout type="log4net.Layout.PatternLayout,log4net">
      <param name="ConversionPattern" value="%d [%t] %-5p %c - %m%n" />
      </layout>
    </appender>

    <appender name="console" type="log4net.Appender.ColoredConsoleAppender, log4net">
      <mapping>
        <level value="FATAL" />
        <foreColor value="Yellow, HighIntensity" />
        <backColor value="Purple, HighIntensity" />
      </mapping>
      <mapping>
        <level value="ERROR" />
        <foreColor value="White" />
        <backColor value="Red" />
      </mapping>
      <mapping>
        <level value="WARN" />
        <foreColor value="Yellow" />
      </mapping>
      <mapping>
        <level value="INFO" />
        <backColor value="Blue" />
        <foreColor value="White" />
      </mapping>
      <mapping>
        <level value="DEBUG" />
        <foreColor value="Green" />
      </mapping>
      <layout type="log4net.Layout.PatternLayout,log4net">
        <param name="ConversionPattern" value="%c %-5p %m%n" />
      </layout>
    </appender>
    
    <root>
      <level value="DEBUG" />
      <appender-ref ref="console">
        <threshold value="ERROR" />
      </appender-ref>
      <appender-ref ref="rollingFile" />
    </root>
  </log4net>

thanks
Francois Botha
mabra | 5 Aug 17:49 2015
Picon

RFC: Property "t/thread"

Hi !

 

For future changes, it would be reasonable good to add

"T/Thread" to the patterns class, which explicitely

output the thread-id as a number. Its a pain with the

threadpool threads, which are all named "Thread Pool Thread"

(or something like this) in Asp.Net.

 

Regard the spelling "T" or "Thread".

 

To always apply a context method for this, isn't

too good ...

 

Thanks anyway and

best regards,

 

Manfred

 

Nicholas Duane | 9 Jul 04:29 2015
Picon

setting or overriding log levels via configuration?

Hello,

Is there a way to set custom log levels via configuration?

Is there a way to change existing log levels via configuration?

At the end of this post http://stackoverflow.com/questions/538095/how-do-i-filter-on-a-custom-level-in-log4net I see someone had said:

"You will need to add
<level> <name value="AUDIT" /> <value value="35000" /> </level> in your log4net config section."

which lead me to believe specifying custom log levels in configuration is possible.  However after searching for a while I have seen no other reference to something similar.

Thanks,
Nick

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,


Gmane