Re: All threads blocked while logging
Please post your config. On Fri, Oct 17, 2014 at 4:55 AM, Calin Pavel calin.pa...@codemart.ro wrote: 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: 1ac3d998 774715fa [HelperMethodFrame: 1ac3d998] System.Threading.Thread.SleepInternal(Int32) 1ac3da90 07fef747b5e9 System.Threading.Thread.Sleep(Int32) 1ac3dac0 07fef5fb9631 System.Threading.ReaderWriterLockSlim.EnterMyLockSpin() 1ac3db90 07fef5cd297e System.Threading.ReaderWriterLockSlim.TryEnterReadLockCore(TimeoutTracker) 1ac3dbf0 07fef5cd28fa System.Threading.ReaderWriterLockSlim.TryEnterReadLock(TimeoutTracker) 1ac3dc40 07fe98fb4efd log4net.Repository.Hierarchy.Logger.CallAppenders(log4net.Core.LoggingEvent) 1ac3dcc0 07fe98fb4907 log4net.Repository.Hierarchy.Logger.Log(System.Type, log4net.Core.Level, System.Object, System.Exception) 1ac3dd30 07fe98fb47f9 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
Re: All threads blocked while logging
Usually when blocking occurs, it has something to do with the LockingModel: http://logging.apache.org/log4net/release/sdk/log4net.Appender.FileAppender.LockingModel.html I don't see that you are setting this to MinimalLock in what you posted, but I would verify that you are leaving this setting as the default ExclusiveLock. We always put a BufferingForwardingAppender ( http://logging.apache.org/log4net/release/sdk/log4net.Appender.BufferingForwardingAppender.html) in front of a RollingFileAppender. This will help as you actually aren't writing every log event when it happens. We use something like the following configuration to buffer X events and write them out when the buffer is full (ensure you have lossy = false so you don't lose events) or an event of WARN or higher is logged. appender name=BufferingForwardingAppender type=log4net.Appender.BufferingForwardingAppender bufferSize value=100 / lossy value=false / evaluator type=log4net.Core.LevelEvaluator threshold value=WARN/ /evaluator appender-ref ref=RollingFileAppender / /appender Note that this makes it harder to watch your logs as they will only be flushed every X (100 in the above example) events. If you need to see immediate logs and have the process using ConfigureAndWatch to configure logging, you can just switch the bufferSize configuration to 1 while you are looking at the logs and set it back when done. You should also ensure you have a call to LogManager.Shutdown ( http://logging.apache.org/log4net/release/sdk/log4net.LogManager.Shutdown.html) when your process is exiting (clean or on error) so log4net can try to get all events flushed before the process exits. Hope this helps Mike On Fri, Oct 17, 2014 at 9:06 AM, Calin Pavel calin.pa...@codemart.ro wrote: Hi, We use attached configuration as an XML file, but in addition to this at runtime we add dynamically some appenderers with the code: private void addLoggerForMonitor(Hierarchy loggerRepository, MonitorConfig monitorConfig) { Logger root = loggerRepository.Root; RollingFileAppender mainAppender = (RollingFileAppender)root.GetAppender(MAIN_FILE_APPENDER_NAME); string logPath = mainAppender.File; string logDir = logPath.Substring(0, logPath.LastIndexOf(@\)); // create the appender RollingFileAppender monitorAppender = new RollingFileAppender(); monitorAppender.Name = buildAppendererName(monitorConfig); monitorAppender.File = Path.Combine(logDir, MONITOR_LOGGING_PARENT_DIR, monitorConfig.name) + @\; // Copy values from the DataCollector appenderer (main appenderer) monitorAppender.DatePattern = DateHelper.DATE_FORMAT + '_ + monitorConfig.name + .log'; monitorAppender.AppendToFile = mainAppender.AppendToFile; monitorAppender.RollingStyle = mainAppender.RollingStyle; monitorAppender.StaticLogFileName = mainAppender.StaticLogFileName; monitorAppender.PreserveLogFileNameExtension = mainAppender.PreserveLogFileNameExtension; PatternLayout layout = new PatternLayout(%date [%thread] %-5level %logger{1}:%L - %message%newline); monitorAppender.Layout = layout; monitorAppender.Threshold = monitorConfig.loggingLevel; PropertyFilter filter = new PropertyFilter(); filter.Key = LoggingConstants.THREAD_LOGGING_KEY; filter.StringToMatch = monitorConfig.name; DenyAllFilter filterDeny = new log4net.Filter.DenyAllFilter(); monitorAppender.AddFilter(filter); monitorAppender.AddFilter(filterDeny); monitorAppender.ActivateOptions(); // create the logger Logger pbeakkLogger = (Logger)LogManager.GetLogger(ROOT_LEVEL).Logger; // Force DEBUG level for logger. Filter by level will be done by appenderer pbeakkLogger.Level = Level.Debug; pbeakkLogger.AddAppender(monitorAppender); } Regards, Calin Pavel On 10/17/2014 4:16 PM, Michael Schall wrote: Please post your config. On Fri, Oct 17, 2014 at 4:55 AM, Calin Pavel calin.pa...@codemart.ro wrote: 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: 1ac3d998 774715fa [HelperMethodFrame: 1ac3d998] System.Threading.Thread.SleepInternal(Int32) 1ac3da90 07fef747b5e9 System.Threading.Thread.Sleep(Int32) 1ac3dac0 07fef5fb9631
Re: Inconsistent results observed while using BufferingForwardAppender
Try adding the thread name to your conversion to ensure it is a different thread conversionPattern value=%level %date{-MM-dd'T'HH:mm:ss.fffzzz http://opengrok.factset.com/source/s?path=ss.fffzzzproject=/platform/wauds/mainline} %property{hostname} [%thread] %property{guid} %message%newline / It seems more likely that a thread is being reused. Mike On Thu, Aug 14, 2014 at 10:51 AM, Ananth Tatachar ananth.tatac...@gmail.com wrote: 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 http://opengrok.factset.com/source/s?path=log4net.Appender.RollingFileAppenderproject=/platform/wauds/mainline file type=log4net.Util.PatternString http://opengrok.factset.com/source/s?path=log4net.Util.PatternStringproject=/platform/wauds/mainline value=C:\Logs\TFile.log / rollingStyle value=Date / datePattern value=-MM-dd / maxSizeRollBackups value=10 / appendToFile value=true / layout type=log4net.Layout.PatternLayout http://opengrok.factset.com/source/s?path=log4net.Layout.PatternLayoutproject=/platform/wauds/mainline conversionPattern value=%level %date{-MM-dd'T'HH:mm: ss.fffzzz http://opengrok.factset.com/source/s?path=ss.fffzzzproject=/platform/wauds/mainline} %property{hostname} %property{guid} %message%newline / /layout /appender appender name=BufferedFileAppender type= log4net.Appender.BufferingForwardingAppender http://opengrok.factset.com/source/s?path=log4net.Appender.BufferingForwardingAppenderproject=/platform/wauds/mainline bufferSize value=512 / evaluator type=log4net.Core.TimeEvaluator http://opengrok.factset.com/source/s?path=log4net.Core.TimeEvaluatorproject=/platform/wauds/mainline 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 http://opengrok.factset.com/source/s?path=log4net.Appender.BufferingForwardingAppenderproject=/platform/wauds/mainline 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?
Re: Too many log files
I just created my own appender in a new assembly. That way I could roll back to the stock implementation if needed. Mike On May 26, 2011, at 11:09 AM, Lansdaal, Michael T michael.t.lansd...@boeing.com wrote: Thanks for posting that (I don’t follow the mailing list too closely and missed it). I like the current implementation if your patch that has MaxDateRollBackups of 4 keeping foo.2010-06-17.log foo.2010-06-16.log foo.2010-06-15.log foo.2010-06-15.1.log foo.2010-06-15.2.log foo.2010-06-14.log I guess the question would be – are the developers interested in folding this into the main branch or are we stuck with making our own patched version? Thanks, Mike From: Michael Schall [mailto:mike.sch...@gmail.com] Sent: Tuesday, May 24, 2011 9:57 AM To: Log4NET User Subject: Re: Too many log files I worked on a solution to this that we are using in production... I posted it on the list without much response... You are welcome to try this... http://article.gmane.org/gmane.comp.apache.logging.log4net.devel/885/match=rolling+files+date+time+boundaries+doesn't+support+maximum+number+backup On Tue, May 24, 2011 at 11:38 AM, Rob Richardson rob.richard...@rad-con.com wrote: Thanks for your reply! I quote a reply to that thread below: I suspect the difficulties deleting files rolled only by date is that the appender would need to take into account the DatePattern used when locating files to be considered for deleting. Counted backups (log.txt.1, log.txt.2, log.txt.3, etc.) are easier to deal with because integer sequences are more well-known. I'm not aware of any efforts to support rolling of files based on RollingMode.Date. I would be happy with counted backups, as mentioned in that reply. How do I set my rolling file appender to do that? Thanks again! RobR From: Lansdaal, Michael T [mailto:michael.t.lansd...@boeing.com] Sent: Tuesday, May 24, 2011 12:33 PM To: Log4NET User Subject: RE: Too many log files This post (http://www.l4ndash.com/Log4NetMailArchive%2Ftabid%2F70%2Fforumid%2F1%2Fpostid%2F17575%2Fview%2Ftopic%2FDefault.aspx) says that maxSizeRollBackups does not work if you set RollingStyle to RollingMode.Date (and another post I saw says it as “rollingStyle of Date does not support maxSizeRollBackups). I have implemented my own directory cleaning code in application to clean out log files older than a certain date. Thanks, Mike From: Rob Richardson [mailto:rob.richard...@rad-con.com] Sent: Tuesday, May 24, 2011 8:37 AM To: Log4NET User Subject: Too many log files Log4net is ignoring the maximum number of files for my rolling file appender: appender name=RollingFile type=log4net.Appender.RollingFileAppender file value=HeatingModelScheduler.log / appendToFile value=true / param name=MaxSizeRollBackups value=5 / param name=DatePattern value=.-MM-dd.lo\g / layout type=log4net.Layout.PatternLayout conversionPattern value=%date - %message%newline / /layout /appender Why do I now have six old log files? Thank you very much. RobR
Re: Too many log files
I worked on a solution to this that we are using in production... I posted it on the list without much response... You are welcome to try this... http://article.gmane.org/gmane.comp.apache.logging.log4net.devel/885/match=rolling+files+date+time+boundaries+doesn't+support+maximum+number+backup On Tue, May 24, 2011 at 11:38 AM, Rob Richardson rob.richard...@rad-con.com wrote: Thanks for your reply! I quote a reply to that thread below: I suspect the difficulties deleting files rolled only by date is that the appender would need to take into account the DatePattern used when locating files to be considered for deleting. Counted backups (log.txt.1, log.txt.2, log.txt.3, etc.) are easier to deal with because integer sequences are more well-known. I'm not aware of any efforts to support rolling of files based on RollingMode.Date. I would be happy with counted backups, as mentioned in that reply. How do I set my rolling file appender to do that? Thanks again! RobR -- *From:* Lansdaal, Michael T [mailto:michael.t.lansd...@boeing.com] *Sent:* Tuesday, May 24, 2011 12:33 PM *To:* Log4NET User *Subject:* RE: Too many log files This post ( http://www.l4ndash.com/Log4NetMailArchive%2Ftabid%2F70%2Fforumid%2F1%2Fpostid%2F17575%2Fview%2Ftopic%2FDefault.aspx) says that maxSizeRollBackups does not work if you set RollingStyle to RollingMode.Date (and another post I saw says it as “rollingStyle of Date does not support maxSizeRollBackups). I have implemented my own directory cleaning code in application to clean out log files older than a certain date. Thanks, Mike *From:* Rob Richardson [mailto:rob.richard...@rad-con.com] *Sent:* Tuesday, May 24, 2011 8:37 AM *To:* Log4NET User *Subject:* Too many log files Log4net is ignoring the maximum number of files for my rolling file appender: appender name=RollingFile type=log4net.Appender.RollingFileAppender file value=HeatingModelScheduler.log / appendToFile value=true / param name=MaxSizeRollBackups value=5 / param name=DatePattern value=.-MM-dd.lo\g / layout type=log4net.Layout.PatternLayout conversionPattern value=%date - %message%newline / /layout /appender Why do I now have six old log files? Thank you very much. RobR
Re: RollingFileAppender
Re-reading your exact requirements, I'm not sure you can get exactly what you want with the built in appenders. The current RollingFileAppender roles on size changing the log count portion of the file name and on date changing the date portion. I think you would need to write your own appender if you want to change the date when size rolls the file. Mike On Jan 16, 2011, at 8:48 PM, cyz zhoup...@micron.com wrote: Hi, do you mind to provide an example? I played around with the Composite setting, but didn't get what I really want. Michael Schall wrote: http://logging.apache.org/log4net/release/config-examples.html http://logging.apache.org/log4net/release/config-examples.htmlLooks like you want to have a rollingStyle=Composite On Fri, Jan 14, 2011 at 12:01 AM, cyz zhoup...@micron.com wrote: Tried the configuration, but the backup file name is still log.txt.1, log.txt.2, doesn't append with datetime as specified in DatePattern Jim Scott-8 wrote: Try this appender name=RollingFileAppender type=log4net.Appender.RollingFileAppender file value=log.txt / appendToFile value=true / rollingStyle value=Size / maxSizeRollBackups value=-1 / maximumFileSize value=10MB / staticLogFileName value=true / countDirection value=0 / layout type=log4net.Layout.PatternLayout conversionPattern value=%date [%thread] %-5level %logger [%property{NDC}] - %message%newline / /layout /appender On 1/13/2011 8:28 PM, cyz wrote: Hi, I'd like to have a logging system with below behaviors, is RollingFileAppender able to achieve? 1 messages are logged to a fixed file name, say log.txt. 2 log files are auto backup by sizes. I.e. when log.txt hits the configured size, it's renamed as logyyMMddHHmmss.txt, next message coming in will be written to log.txt again. 3 there is no limit on how many files can be backup. Thank you. -- View this message in context: http://old.nabble.com/RollingFileAppender-tp30668883p30669112.html Sent from the Log4net - Users mailing list archive at Nabble.com. -- View this message in context: http://old.nabble.com/RollingFileAppender-tp30668883p30676167.html Sent from the Log4net - Users mailing list archive at Nabble.com.
Re: Is there an SMTP appender limit
10 should be fine, but you could always use a distribution list. Mike On Oct 1, 2010, at 11:26 PM, Ron Grabowski rongrabow...@yahoo.com wrote: Whatever the Framework's limit is for MailMessage's To property. You'll probably be limited by whatever the mail server is setup to accept. - Original Message From: harry.dougl...@pnc.com harry.dougl...@pnc.com To: Log4NET User log4net-user@logging.apache.org Sent: Thu, September 30, 2010 10:41:19 AM Subject: Is there an SMTP appender limit Just curious if there is any limit for the to value for the SmtpAppender. I have about 10 emails I need to put in the to value, so is that ok? Thanks, Harry The contents of this email are the property of PNC. If it was not addressed to you, you have no legal right to read it. If you think you received it in error, please notify the sender. Do not forward or copy without permission of the sender. This message may contain an advertisement of a product or service and thus may constitute a commercial electronic mail message under US Law. The postal address for PNC is 249 Fifth Avenue, Pittsburgh, PA 15222. If you do not wish to receive any additional advertising or promotional messages from PNC at this e-mail address, click here to unsubscribe. https://pnc.p.delivery.net/m/u/pnc/uni/p.asp By unsubscribing to this message, you will be unsubscribed from all advertising or promotional messages from PNC. Removing your e-mail address from this mailing list will not affect your subscription to alerts, e-newsletters or account servicing e-mails.
Re: Log in more than 1 log destination for different assemblies.
When you say multiple assemblies, I assume you mean multiple processes? Logging this way is not suggested as for each log message you have to reopen the file. If you have really light logging, it would probably be ok... Look at the LockingModel: http://logging.apache.org/log4net/release/sdk/log4net.Appender.FileAppender.LockingModel.html From http://logging.apache.org/log4net/release/config-examples.html: This example shows how to configure the appender to use the minimal locking model that allows multiple processes to write to the same file. appender name=FileAppender type=log4net.Appender.FileAppender file value=${TMP}\log-file.txt / appendToFile value=true / lockingModel type=log4net.Appender.FileAppender+MinimalLock / layout type=log4net.Layout.PatternLayout conversionPattern value=%date [%thread] %-5level %logger [%property{NDC}] - %message%newline / /layout /appender On Wed, Sep 2, 2009 at 3:28 AM, mattyboyma...@spdprintsolutions.com wrote: Hi Christian, I'm actually looking to achieve the opposite, I want to know if it's possible to get several assemblies to log to the SAME log file. Have you managed to achieve this? If so, do you have any example code/configs etc.? Many Thanks cristianmad wrote: Hi, I am new to log4net and just starting reading some documentation about it. We need to see if it would be a suitable logging solution for our applications. Our product (like most of them) uses a number of assemblies. I was wondering if it would be possible for each assembly to log in its own log file (or any other destination) even if they are loaded in the same application domain. For example consider we have the following assemblies: A.dll and B.dll. Is it possible for the two assemblies to log in their own log files even if they are loaded in the same application domain? If yes, could you please give me a very simple example? Thank you, Cristian -- View this message in context: http://www.nabble.com/Log-in-more-than-1-log-destination-for-different-assemblies.-tp24807634p25253548.html Sent from the Log4net - Users mailing list archive at Nabble.com.
Re: Log in more than 1 log destination for different assemblies.
Instead of using the GlobalContext.Properties to define where your logs are coming from I would define a Shared/Static logger per class based on the fully qualified class name allowing you to use the logger hierarchy as defined here http://logging.apache.org/log4net/release/manual/introduction.html The FAQ has a section too... http://logging.apache.org/log4net/release/faq.html#Implementing%20Logging This way you can turn off specific loggers, direct them to different appenders, ... Mike On Wed, Sep 2, 2009 at 9:01 AM, mattyboyma...@spdprintsolutions.com wrote: Thanks for the replying. When I say mutliple assemblies I have a GUI app. and it uses log4net to log to a file let's say 'C:\Claymore.log'. I have developed several .dll files which I call from within the GUI app. I want the code within the .dll files to also log to 'C:\Calymore.log'. I've actually just managed to get it working but I'm not using locking and wonder whether I should be or not for this scenario. As far as I'm aware everything will run in the same process and should be fine without locking..? Here's what I've done: In both the GUI front-end and each .dll I have added the following entry to the AssemblyInfo.vb (yes, I'm using vb.net!) file Assembly: log4net.Config.XMLConfigurator(ConfigFile:=Claymore.exe.log4net, Watch:=True) In GUI Front-End Assembly ONLY I've added 'Claymore.exe.log4net' file. Then in GUI Front-End class: Public Class frmDashboard Public Shared logger As log4net.ILog Private Sub frmDashboard_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load log4net.GlobalContext.Properties(AssemblyName) = Assembly.GetExecutingAssembly.GetName.Name() logger = log4net.LogManager.GetLogger(ClaymoreLogger) logger.Info(Dashboard_Load() - Start) logger.Debug(Dashboard_Load() - Finish) Dim clsGUI As New ClaymoreGUI.clsDashboard() End Sub End Class In my ClaymoreGUI.dll: Public Class clsDashboard Public Shared logger As log4net.ILog Public Sub New() log4net.GlobalContext.Properties(AssemblyName) = Assembly.GetExecutingAssembly.GetName.Name() logger = log4net.LogManager.GetLogger(ClaymoreLogger) logger.Info(New() - Start) logger.Debug(New() - Finish) End Sub End Class Seems to work well :-) Michael Schall wrote: When you say multiple assemblies, I assume you mean multiple processes? Logging this way is not suggested as for each log message you have to reopen the file. If you have really light logging, it would probably be ok... Look at the LockingModel: http://logging.apache.org/log4net/release/sdk/log4net.Appender.FileAppender.LockingModel.html From http://logging.apache.org/log4net/release/config-examples.html: This example shows how to configure the appender to use the minimal locking model that allows multiple processes to write to the same file. appender name=FileAppender type=log4net.Appender.FileAppender file value=${TMP}\log-file.txt / appendToFile value=true / lockingModel type=log4net.Appender.FileAppender+MinimalLock / layout type=log4net.Layout.PatternLayout conversionPattern value=%date [%thread] %-5level %logger [%property{NDC}] - %message%newline / /layout /appender On Wed, Sep 2, 2009 at 3:28 AM, mattyboyma...@spdprintsolutions.com wrote: Hi Christian, I'm actually looking to achieve the opposite, I want to know if it's possible to get several assemblies to log to the SAME log file. Have you managed to achieve this? If so, do you have any example code/configs etc.? Many Thanks cristianmad wrote: Hi, I am new to log4net and just starting reading some documentation about it. We need to see if it would be a suitable logging solution for our applications. Our product (like most of them) uses a number of assemblies. I was wondering if it would be possible for each assembly to log in its own log file (or any other destination) even if they are loaded in the same application domain. For example consider we have the following assemblies: A.dll and B.dll. Is it possible for the two assemblies to log in their own log files even if they are loaded in the same application domain? If yes, could you please give me a very simple example? Thank you, Cristian -- View this message in context: http://www.nabble.com/Log-in-more-than-1-log-destination-for-different-assemblies.-tp24807634p25253548.html Sent from the Log4net - Users mailing list archive at Nabble.com. :-):-):-) -- View this message in context: http://www.nabble.com/Log-in-more-than-1-log-destination-for-different-assemblies.-tp24807634p25258147.html Sent from the Log4net - Users mailing list archive at Nabble.com.
Re: forced log
You could define a separate logger for your the ones you always want log... logger = log4net.LogManager.GetLogger(AlwaysLog) logger.info(hello world) logger name=AlwaysLog level value=ALL / appender-ref ref=... / /logger Depending on how you usually get a logger... .GetLogger(GetType(Foo)) This has the downside of not knowing which class you are logging from... Might work for your circumstance... Mike On Wed, Sep 2, 2009 at 10:36 AM, scamper_22scamper...@hotmail.com wrote: Hi all, I'm looking for a way to force a log without using Fatal. For example, let us say I want to print a log with the application name and version. I want this printed regardless of what the log level is. Right now, I am just using the fatal log level. The problem with this is it ruins some of the data collection we have where we have a count of the number of errors/fatal logs. Is there some way to do a logger.ForcedLog( INFO, my string) ? Which basically ignores the priority of the message, but still logs it? I have see this ForcedLog API in log4j (http://logging.apache.org/log4j/1.2/apidocs/index.html) but it does not seem to in log4net (1.2.10.0). Thanks, -- View this message in context: http://www.nabble.com/forced-log-tp25259981p25259981.html Sent from the Log4net - Users mailing list archive at Nabble.com.
Re: Experiencing locks while using AdoNetAppender
Not sure if this has changed, but I'm pretty sure there is a database lock on inserts/updates. So only one insert at a time. You might try the BufferedForwardingAppender. It might serialize the inserts for you. On Aug 18, 2009, at 8:36 PM, Ron Grabowski rongrabow...@yahoo.com wrote: I think that's how SQLite works. Have you tried writing to a single .db file from multiple threads without using log4net? From: Patrick Kalkman p...@hoogendoorn.nl To: log4net-user@logging.apache.org Sent: Tuesday, August 18, 2009 8:29:17 AM Subject: Experiencing locks while using AdoNetAppender Hi, I am using the AdoNetAppender for logging messages from multiple application. All the applications log into one sqllite database. Sometimes when a lot of information is logged I am experiencing exceptions like: log4net:ERROR [AdoNetAppender] Exception while writing to database System.Data.SQLite.SQLiteException: The database file is locked database is locked at System.Data.SQLite.SQLite3.Reset(SQLiteStatement stmt) at System.Data.SQLite.SQLite3.Step(SQLiteStatement stmt) at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery() at System.Data.SQLite.SQLiteTransaction..ctor(SQLiteConnection connection, Boolean deferredLock) at System.Data.SQLite.SQLiteConnection.BeginTransaction(Boolean deferredLock) at System.Data.SQLite.SQLiteConnection.BeginDbTransaction (IsolationLevel isolationLevel) at System.Data.Common.DbConnection.System.Data.IDbConnection.BeginTransaction( ) at log4net.Appender.AdoNetAppender.SendBuffer(LoggingEvent[] events) The default CommandTimeout in the AdoNetAppender on the IDbCommand is 30 seconds, but I would like to influence this timeout in the log4net configuration (file) so that I can influence the timeout on the logging if the database is locked for a longer portion of time. Reducing the timeout may lead to events getting lost, but I prefer that to our application hanging for the full CommandTimeout waiting for the database to become unlocked. Is it possible to configure the timeout using configuration? or would it be better to choose for a solution like deriving from the AdoNetAppender and add the functionality? Thanks in advance for any answers. Patrick **DISCLAIMER** Deze E-mail is uitsluitend bestemd voor de geadresseerde(n). Verstrekking aan en gebruik door anderen is niet toegestaan. De Hoogendoorn Groep sluit iedere aansprakelijkheid uit die voortvloeit uit elektronische verzending. This E-mail is intended exclusively for the addressee(s), and may not be passed on to, or made available for use by any person other than the addressee(s). The Hoogendoorn Group rules out any and every liability resulting from any electronic transmission. *** This message has been scanned by Network Associates' McAfee AntiVirus Technology
Re: relative path for config file
We configure our logging in code using an external xml file using log4net.Config.XmlConfigurator.ConfigureAndWatch. This way I can change my logging settings without resetting my website. Mike 2009/8/6 Karim Bourouba kar...@hotmail.com: Hi There, I understand you desire to have a central directory for log files - but surely if they are all going to live in the \Configs dir, then this directory will always be in the same place on each machine? Other than that, I think unless you want to have a seperate utility to manage your logfiles for you, then you will probably need to set the path in the code :( Raszka - sometimes it is very useful to hold some configuration in an external xml file. Subject: RE: relative path for config file Date: Thu, 6 Aug 2009 08:14:47 +0200 From: ras...@hasam.cz To: log4net-user@logging.apache.org Hi, you can try this: add key=log4net.Config.File value=~\configs\log4net.config / but I'm not sure if this works. What you are using external config file? log4net config can be written directly in web.config. RR Od: Christian Chenier [mailto:cchen...@uottawa.ca] Odesláno: 5. srpna 2009 18:16 Komu: log4net-user@logging.apache.org Předmět: relative path for config file Hi, I use log4net in a C# web application and am having problems configuring it to use a relative path to point to the location of a configuration file external to web.config. In web.config, if I use add key=log4net.Config.File value=C:\somePath\log4net.config / all works fine. However, I would like to avoid having to hard-code the physical path and would like to specify something like add key=log4net.Config.File value=configs\log4net.config / where the configs directory is located in the same directory as web.config (the AppDomain.CurrentDomain.BaseDirectory). However this does not work (I no longer get anything output to my log file when I make that change). I understand that one can programmatically construct a full path from the base directory, but there is surely a way to specify a relative path directly in the web.config file? I have tried modifying the string using leading slash (and backslash), etc. to no avail, and could not find a solution anywhere. Does anyone know how to do this? (As an aside, using a relative path to specify the output file name within the appender works fine, relative to the base directory.) Thanks, Chris Chenier Windows Live Messenger: Happy 10-Year Anniversary-get free winks and emoticons. Get Them Now
Re: DEBUG vs INFO
What appenders are you using? I assume one of them is the rolling file appender? How large is the log file produced with the setting at DEBUG vs INFO? If you need to keep the debug information you can look at the BufferingForwardingAppender. The following will buffer 255 messages before writing to the file, unless there is a WARN or higher message, then the buffer is flushed immediately. This should hopefully let the error message that crashes the system still make it to the log file.:) I don't know how your loggers are setup, but you can turn off at that level as well. log4net appender name=BufferingForwardingAppender type=log4net.Appender.BufferingForwardingAppender bufferSize value=255 / lossy value=false / evaluator type=log4net.Core.LevelEvaluator threshold value=WARN/ /evaluator appender-ref ref=RollingFile / /appender appender name=RollingFile type=log4net.Appender.RollingFileAppender file value=..\..\log\web.log / appendToFile value=true / maximumFileSize value=100MB / maxSizeRollBackups value=-1 / layout type=log4net.Layout.PatternLayout conversionPattern value=%5level [%date] [%thread] %-30.30logger{2} %message%newline / /layout /appender root level value=DEBUG / appender-ref ref=BufferingForwardingAppender / /root /log4net On Wed, Feb 25, 2009 at 8:31 AM, Walden H. Leverich wald...@techsoftinc.com wrote: Graham, That's not a log4net issue as much as it's an issue in your application. Sounds like your application (like many) makes lots of log.Debug() calls, to log, um, debug information. By switching the logging from DEBUG to INFO you've stopped all those log entries from being written to disk. Even more, if your app developers were smart about it, they checked the IsDebugEnabled property before making the log.Debug() call, so you're not even evaluating the parms to that call, and sometimes that can be quite expensive. So, it's a known issue that logging more stuff takes more time, but I wouldn't call it a bug. -Walden -- Walden H Leverich III Tech Software (516) 627-3800 x3051 wald...@techsoftinc.com http://www.TechSoftInc.com Quiquid latine dictum sit altum viditur. (Whatever is said in Latin seems profound.)
Re: How to use separate config file for log4net
No, it is only required once for the process. Sent from my iPod On Dec 6, 2008, at 7:28 AM, wijitha [EMAIL PROTECTED] wrote: Hi First, thanks for replying me. now that is working. but now i wanna know, Should this piece of code be written in constructor of each class i write. FileInfo log4NetConfigFile = new FileInfo(log4net.config); if (log4NetConfigFile == null || !log4NetConfigFile.Exists) throw new Exception(unable to find log file); log4net.Config.XmlConfigurator.ConfigureAndWatch(log4NetConfigFile); thank you wijitha [EMAIL PROTECTED] wrote: // initialize the log4net config file // the system expects to find it in the same folder as the exe file = /bin/debug FileInfo log4NetConfigFile = new FileInfo ( MyCustomConfigFile.config ); if (log4NetConfigFile == null || ! log4NetConfigFile.Exists) throw new Exception ( unable to find log4net log file ); XmlConfigurator .Configure(log4NetConfigFile); From: wijitha [EMAIL PROTECTED] Sent: Friday, December 05, 2008 10:14 AM To: log4net-user@logging.apache.org Subject: How to use separate config file for log4net Hi all I want to use log4net with my project. here is the simple example i tried. App.config : type=log4net.Config.Log4NetConfigurationSectionHandler, log4net/ A1 is set to be a ConsoleAppender A1 uses PatternLayout Set root logger level to DEBUG and its only appender to A1 here is the code: private static readonly ILog log = LogManager.GetLogger(typeof(Program)); static void Main(string[] args) { XmlConfigurator.Configure(); log.Info(Entering application.); log.Debug(Exiting application.); Console.Write(This Log4Net example); } This thing is working well. And what i want to do is put the log4net configuration part in a separate file call Log4Net.config if any one know how to do this please reply me. It is better if u can separately give me the two configuration files. (App.config and Log4Net.config) thanks a lot wijitha -- View this message in context: http://www.nabble.com/How-to-use-separate-config-file-for-log4net-tp20856712 p20856712.html Sent from the Log4net - Users mailing list archive at Nabble.com. -- View this message in context: http://www.nabble.com/How-to-use-separate-config-file-for-log4net-tp20856712p20870124.html Sent from the Log4net - Users mailing list archive at Nabble.com.
Re: How to use separate config file for log4net
You don't need anything in your app.config. Just use the log4net.Config.XmlConfigurator.ConfigureAndWatch method instead as pass it a file with your log4net definitions. Log4Net.config: log4net ... root ... /root /log4net This will also allow you to change logging settings while the program is running. Mike On Fri, Dec 5, 2008 at 9:46 AM, wijitha [EMAIL PROTECTED] wrote: Hi all I want to use log4net with my project. here is the simple example i tried. App.config : ?xml version=1.0 encoding=utf-8 ? configuration configSections section name=log4net type=log4net.Config.Log4NetConfigurationSectionHandler, log4net/ /configSections log4net A1 is set to be a ConsoleAppender appender name=A1 type=log4net.Appender.ConsoleAppender A1 uses PatternLayout layout type=log4net.Layout.PatternLayout conversionPattern value=%-4timestamp [%thread] %-5level %logger %ndc - %message%newline / /layout /appender Set root logger level to DEBUG and its only appender to A1 root level value=DEBUG / appender-ref ref=A1 / /root /log4net /configuration here is the code: private static readonly ILog log = LogManager.GetLogger(typeof(Program)); static void Main(string[] args) { XmlConfigurator.Configure(); log.Info(Entering application.); log.Debug(Exiting application.); Console.Write(This Log4Net example); } This thing is working well. And what i want to do is put the log4net configuration part in a separate file call Log4Net.config if any one know how to do this please reply me. It is better if u can separately give me the two configuration files. (App.config and Log4Net.config) thanks a lot wijitha -- View this message in context: http://www.nabble.com/How-to-use-separate-config-file-for-log4net-tp20856712p20856712.html Sent from the Log4net - Users mailing list archive at Nabble.com.
Re: custom fields?
Take a look at the documentation around contexts and how they override each other... Hopefully this will give you want you want... http://logging.apache.org/log4net/release/manual/contexts.html We use both the GlobalContext and the ThreadContext and they work great. Mike On Thu, Oct 2, 2008 at 1:31 PM, Bill McCormick [EMAIL PROTECTED]wrote: Thanks, so much Francine!! If I understand correctly, once the GC property is set, it would stay set for every logged message thereafter? It would actually be better if it would be reset, since I would need (potentially) new values with each new logged message. Thanks, Bill On Thu, Oct 2, 2008 at 12:01 PM, Francine Taylor [EMAIL PROTECTED] wrote: Sure. Here's how you can create a custom dynamic field: Put this in your application's log4net setup: // This is a way of creating a dynamic property (found in ActiveProperties.cs) // To use it, put a reference to the property in the appender's property: %property{custom1} // It isn't actually used for anything right now, but I wanted it left in as an example log4net.GlobalContext.Properties[custom1] = new Custom1(); log4net.GlobalContext.Properties[custom2] = new Custom2(); log4net.GlobalContext.Properties[custom2] = new Custom3(); And then add this class to your project: // You can use this class to create an active property to be used in the log4net configuration // // In your application setup routine you would create the property: // log4net.GlobalContext.Properties[sampler] = new SampleProperty(); // // Then in the log4net.xml file, a pattern might contain this reference: %property{sampler} // using System; using System.Collections.Generic; using System.Text; namespace Genesis.Logging { public static class ActiveProperties { public static string custom1 = custom1 value; public static string custom2 = custom2 value; public static string custom3 = custom3 value; } public class Custom1 { public override string ToString() { return ActiveProperties.custom1; } } public class Custom2 { public override string ToString() { return ActiveProperties.custom2; } } public class Custom3 { public override string ToString() { return ActiveProperties.custom3; } } } Then, in your InfoFormat method, just set the sampleProperty to whatever you passed in, just before you log the error. -- *From:* Bill McCormick [mailto:[EMAIL PROTECTED] *Sent:* Thursday, October 02, 2008 9:39 AM *To:* log4net-user *Subject:* custom fields? Hello, Is it possible to add custom fields to log4net. I'd like to be able to do something like this: log.InfoFormat(Custom1, Custom2, Custom3, {0},Message); and then have an appender look something like: layout type=log4net.Layout. PatternLayout conversionPattern value=%custom1 %custom2 %custom3 %message%newline / /layout Thanks, Bill = NOTICE: The contents of this e-mail message and any attachments are intended solely for the addressee(s) named in this message. This communication is intended to be and to remain confidential. If you are not the intended recipient of this message, or if this message has been addressed to you in error, please immediately alert the sender by reply e-mail and then delete this message and its attachments. Do not deliver, distribute or copy this message and/or any attachments and if you are not the intended recipient, do not disclose the contents or take any action in reliance upon the information contained in this communication or any attachments. Thank you.
Re: RollingLogFileAppender
This is not an answer, but I open log files with notepad++ all the time and I don't have the MinimalLock flag set. There must be a way... On Feb 18, 2008 4:45 AM, Beyers Cronje [EMAIL PROTECTED] wrote: Hi all, Quick question. I am using a RollingLogFileAppender on a webservice. Logging works 100%, but whenever I try to open the log file for reading in another process I get a sharing violation on the log file. I open the file with: FileStream file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read); Would I have to enable MinimalLock, or is there a way to use ExclusiveLock and have another process read from the log file ? Kind regards Beyers Cronje
Re: Newbie: Log4Net or MS Logging Application Block?
We wrap log4net and have had no issues and we have a logger for each class. I have not swapped it out as your argument suggests, but I don't like to use any library directly. It shields you not only from swapping out a library, but from breaking changes in the library you are wrapping. Most of my wrapper is below... Am I missing something? I'm hopping this would allow me to switch to say nLog if I wanted... Public Interface ILogger Sub Debug(ByVal format As String, ByVal ParamArray args() As Object) Sub Info(ByVal format As String, ByVal ParamArray args() As Object) Sub Warn(ByVal format As String, ByVal ParamArray args() As Object) Sub [Error](ByVal format As String, ByVal ParamArray args() As Object) Sub Fatal(ByVal format As String, ByVal ParamArray args() As Object) Sub Debug(ByVal format As String, ByVal exception As Exception, ByVal ParamArray args() As Object) Sub Info(ByVal format As String, ByVal exception As Exception, ByVal ParamArray args() As Object) Sub Warn(ByVal format As String, ByVal exception As Exception, ByVal ParamArray args() As Object) Sub [Error](ByVal format As String, ByVal exception As Exception, ByVal ParamArray args() As Object) Sub Fatal(ByVal format As String, ByVal exception As Exception, ByVal ParamArray args() As Object) ReadOnly Property IsDebugEnabled() As Boolean ReadOnly Property IsInfoEnabled() As Boolean ReadOnly Property IsWarnEnabled() As Boolean ReadOnly Property IsErrorEnabled() As Boolean ReadOnly Property IsFatalEnabled() As Boolean End Interface Public NotInheritable Class LogManager Public Shared Sub Configure(ByVal configFile As FileInfo) If configFile Is Nothing Then Throw New System.ArgumentNullException(configFile) End If System.Diagnostics.EventLog.WriteEntry( _ String.Format({0}.LogManager, Process.GetCurrentProcess.ProcessName), _ String.Format(Configuring logging using configuration file {0}, configFile.FullName)) log4net.Config.XmlConfigurator.ConfigureAndWatch(configFile) GetLogger(GetType(LogManager)).Debug(Configured logging using configuration file {0}, configFile.FullName) End Sub Public Shared Function GetLogger(ByVal type As System.Type) As ILogger Dim logger As log4net.ILog = _ log4net.LogManager.GetLogger( System.Reflection.Assembly.GetCallingAssembly(), type) Return New Log4NetAdapter(logger) End Function End Class Friend Class Log4NetAdapter Implements ILogger Private _inner As ILog Friend Sub New(ByVal log4netLogger As ILog) _inner = log4netLogger End Sub 'Implement interface methods delegating to _inner End Class On 10/24/07, Owen Corpening [EMAIL PROTECTED] wrote: I second that, but beyond me-too, the only thing I need that I don't have currently is aspect-based logging or the equivalent. In general I have concluded that .net aspect technologies are not-there-yet. I want to be able to add logging at build or runtime, ideally for runtime I can just add a jar with some kind of config file to an existing app and get the logging I need … Obviously no amount of wrapping will even lead in such a direction … Or maybe just-in-time logging, where it will somehow without a performance penalty buffer the last bit of logging then when an exception happens start logging 5 minutes ago …. As for wrapping for down the road I have not seen many applications even make it down the road … they all keep getting rewritten or close to it as new technologies keep arriving … so log4net being the best-in-breed I say use it …. owen -- *From:* Peter Drier [mailto:[EMAIL PROTECTED] *Sent:* Wednesday, October 24, 2007 9:05 AM *To:* Log4NET User *Subject:* Re: Newbie: Log4Net or MS Logging Application Block? I've seen many people wrap log4net just so they could swap it out down the road.. Doing that, you lose the context sensitivity of having a logger in each class.. one of log4net's greatest strengths.. And I've never ever seen it actually replaced down the road.. It makes much more sense to create a custom appender to write to whatever system you need down the road, while still using log4net as the plumbing within your application. I'd advise HEAVILY against wrapping log4net to everyone. You will be trading a strength for a sense of flexibility you'll never actually use. -Peter On 10/23/07, *shaeney* [EMAIL PROTECTED] wrote: José Joye wrote: However. in order not to be too hardly tight to log4net, we decided to build a facade to abstract the Logging framework. This was done in order to easily switch the logging framework we use behind the scene. José Thanks Jose, I had
Re: UDP Appender Issues
I'm not an expert, but I have it working and here is the config. You are missing the LocalPort param. I don't know if it is required. appender name=UdpAppender type=log4net.Appender.UdpAppender param name=LocalPort value=23098 / param name=RemoteAddress value=127.0.0.1 / param name=RemotePort value= / layout type=log4net.Layout.XmlLayoutSchemaLog4j, log4net locationInfo value=true / /layout /appender On 8/3/07, Scott Glass [EMAIL PROTECTED] wrote: Hello, I'm trying to log events to ChainSaw using the UdpAppender. However, even after following the directions on the web site I keep getting the message: log4net:ERROR [UdpAppender] Unable to send logging event to remote host ::1 on port 8080. System.Net.Sockets.SocketException: An address incompatible with the requested protocol was used at System.Net.Sockets.Socket.SendTo(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, EndPoint remoteEP) at System.Net.Sockets.UdpClient.Send(Byte[] dgram, Int32 bytes, IPEndPoint endPoint) at log4net.Appender.UdpAppender.Append(LoggingEvent loggingEvent) A first chance exception of type 'System.NullReferenceException' occurred in com.sungard.servicemanagement.AuthListService_200708.InfoModel.DLL The thread 0x918 has exited with code 0 (0x0). appender name=UdpAppender type=log4net.Appender.UdpAppender remoteAddress value=127.0.0.1 / remotePort value=8080 / layout type=log4net.Layout.XmlLayoutSchemaLog4j locationInfo value=true / /layout /appender Firewall rules are in place to allow UDP:8080 traffic and netStat shows an open listener on port 8080. I'm at a loss, any ideas? Thanks, Scott
Re: File Paths
I had a similar problem where the same exe could be launched multiple times at the same time. You can modify the filename of the log by properties in log4net. I used the processid there may be something like assemblyName or something... appender name=RollingFile type=log4net.Appender.RollingFileAppender file type=log4net.Util.PatternString value=log\foo-pid%processid- / rollingStyle value=Composite / appendToFile value=false / datePattern value=MMdd / maximumFileSize value=100MB / maxSizeRollBackups value=-1 / StaticLogFileName value=false / layout type=log4net.Layout.PatternLayout conversionPattern value=%5level [%date] [%thread] %- 30.30logger{2}%message%newline / /layout /appender On 7/25/07, Vanderkolk, John [EMAIL PROTECTED] wrote: Hello, I'm writing a logger utility for a solution that has several different points of execution. They will all be under some particular folder, but relative to this folder their locations are different. All of these applications are to read the same config file which specifies locations for file appenders, one for each of the points of execution. My problem is that since log4net reads the paths specified in the config file as relative to the executing module, when each executable is run, it makeslog files in different locations when I want them all to make log files in the same location. EX: Here is an example with 2 executables: …\Installation Folder\ log.config Program 1\ Sln1.exe Program2\ Bin\ Sln2.exe Logs\ Log1.txt Log2.txt The problem is that since both exe's read the same config file, I can't get them both to write logs to the same place. Short of writing my own utility to configure the loggers I don't see any other way. Any help would be appreciated, John VanderKolk [EMAIL PROTECTED] The contents of this e-mail are intended for the named addressee only. It contains information that may be confidential. Unless you are the named addressee or an authorized designee, you may not copy or use it, or disclose it to anyone else. If you received it in error please notify us immediately and then destroy it.
Re: no log file is created
Put the following in your Application_Start in your Global.asax... Dim applicationBase As String = System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase Dim log4netPath As String = Path.Combine(applicationBase, Web.log4net.config) If File.Exists(log4netPath) Then log4net.Config.XmlConfigurator.ConfigureAndWatch(NewFileInfo(log4netPath)) Else Throw New System.InvalidOperationException(Unable to find logging configuration file at log4netPath) End If Note that if this fails for some reason (file not present) or other configuration issues, you will not have logging configured. We kill the app domain so that logging (and other configuration) is configured or the system will not start up. Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) Dim lg As ILogger = Nothing ... Try *Code above ... *Catch ex As Exception Dim t As New Threading.Thread(AddressOf ShutdownApp) t.Start() Throw End Try ... End Sub Private Sub ShutdownApp() AppDomain.Unload(AppDomain.CurrentDomain) End Sub On 6/27/07, Samuel Rochas [EMAIL PROTECTED] wrote: Dear Michael, I've tried to define an EventLogAppender as shown bellow, but still nothing happens. I may have a bigger problem ;-) In the Solution Explorer view, I can see the Bin directory with the log4net.dll inside, so for me it looks good. If I use an external config file for log4net, where do I tell my application to use it? Thanx Samuel web.config: configuration xmlns=http://schemas.microsoft.com/.NetConfiguration/v2.0;http://schemas.microsoft.com/.NetConfiguration/v2.0 !-- Register a section handler for the log4net section -- configSections section name=log4net type= System.Configuration.IgnoreSectionHandler / /configSections appSettings /appSettings !-- This section contains the log4net configuration settings -- log4net !-- Define some output appenders -- appender name=EventLogAppender type= log4net.Appender.EventLogAppender layout type=log4net.Layout.PatternLayout conversionPattern value=%date [%thread] %-5level %logger [%property{NDC}] - %message%newline / /layout /appender appender name=A1 type=log4net.Appender.RollingFileAppender file value=C:\Dev\Test\log\log.txt / appendToFile value=true / maxSizeRollBackups value=10 / maximumFileSize value=1024KB / rollingStyle value=Size / staticLogFileName value=true / layout type=log4net.Layout.PatternLayout conversionPattern value=%date [%thread] %-5level %logger [%ndc] - %message%newline / /layout /appender root level value=DEBUG / appender-ref ref=EventLogAppender / /root logger name=com.mypackage.test level value=DEBUG / appender-ref ref=EventLogAppender / /logger /log4net Michael Schall escribió: Are any of the other appenders working(EventViewer, Console)? If not are you configuring log4net? I see you have your configuration in your web config file. We don't do it this way. If the others are working, it has to be in your config file or environment... We use external config files and configure it manually during Application_Start in the global.asax. Below is a sample of our Web.log4net.config file. This way we can change logging without resetting the web site. log4net appender name=RollingFile type= log4net.Appender.RollingFileAppender file value=..\..\log\Regen.log / rollingStyle value=Composite / appendToFile value=false / datePattern value=MMdd / maximumFileSize value=100MB / maxSizeRollBackups value=-1 / StaticLogFileName value=false / layout type=log4net.Layout.PatternLayout conversionPattern value=%5level [%date] [%thread] %- 30.30logger{2} %message%newline / /layout /appender appender name=EventLog type=log4net.Appender.EventLogAppender applicationName value=Regen / filter type=log4net.Filter.LevelRangeFilter levelMin value=INFO / /filter layout type=log4net.Layout.PatternLayout conversionPattern value=%logger %newline %message / /layout /appender root level value=DEBUG / appender-ref ref=RollingFile / appender-ref ref=EventLog / /root /log4net On 6/27/07, Samuel Rochas [EMAIL PROTECTED] wrote: Dear Michael, I have changed my app to write a file using a TextWriter and this is working so I believe my app has rights to write files. But I still have the log problem, no log file is created. Do you have any suggestion on what should I try now? Regards Samuel Michael Schall escribió: You don't need to escape them. Here is my appender declaration... appender name=RollingFile type= log4net.Appender.RollingFileAppender file value=C:\Projects\Company_Name\Project_Name\log\web.log / appendToFile value=true
Re: no log file is created
You don't need to escape them. Here is my appender declaration... appender name=RollingFile type=log4net.Appender.RollingFileAppender file value=C:\Projects\Company_Name\Project_Name\log\web.log / appendToFile value=true / maximumFileSize value=100MB / maxSizeRollBackups value=-1 / layout type=log4net.Layout.PatternLayout conversionPattern value=%5level [%date] [%thread] %- 30.30logger{2}%message%newline / /layout /appender On 6/22/07, Samuel Rochas [EMAIL PROTECTED] wrote: Dear Michael, I run the web server which comes with studio. I am not sure how / where to configure it. I open the IIS tool, and in the Default web site properties, I setup the directory rights to write. But no change is to see. Do you need to escape the '\' characters like you do in Java for the absolute file path like C:\\path1\\path2\\file.txt? Thank you Samuel Michael Schall escribió: The user the application is running as has to have rights to write to / create files in the folder where you are logging. Keep in mind that if you are debugging, that might be a different relative path than if you are running the program directly. I use an absolute path for my rolling file appenders and they work great. Mike
Re: no log file is created
The user the application is running as has to have rights to write to / create files in the folder where you are logging. Keep in mind that if you are debugging, that might be a different relative path than if you are running the program directly. I use an absolute path for my rolling file appenders and they work great. Mike On 6/21/07, Samuel Rochas [EMAIL PROTECTED] wrote: Dear all, I use to work with Log4j but I am new to Log4net. I try to setup a small example but no file is created while logging, though the line with the log instruction is executed. This is my setup, any hint? Thank you in advance. *** web.config *** configuration !-- Register a section handler for the log4net section -- configSections section name=log4net type=System.Configuration.IgnoreSectionHandler / /configSections appSettings !-- To enable internal log4net logging specify the following appSettings key -- !-- add key=log4net.Internal.Debug value=true/ -- /appSettings !-- This section contains the log4net configuration settings -- log4net !-- Define some output appenders -- appender name=A1 type=log4net.Appender.RollingFileAppender file value=log.txt / appendToFile value=true / maxSizeRollBackups value=10 / maximumFileSize value=1024KB / rollingStyle value=Size / staticLogFileName value=true / layout type=log4net.Layout.PatternLayout !-- header value=[Header]#13;#10; / footer value=[Footer]#13;#10; /-- conversionPattern value=%date [%thread] %-5level %logger [%ndc] - %message%newline / /layout /appender root level value=DEBUG / appender-ref ref=A1 / /root logger name =L1 level value=DEBUG / appender-ref ref=A1 / /logger /log4net * *** My code *** public static class Query { // Logger instance private static readonly ILog log = LogManager.GetLogger(typeof(Query)); public static ArrayList myMethod(string id_p, string course_p) { log.Debug(Entering application.); *
Compress Delete old logs
Is there a way with the rollingfile appender to have it compress itself as it is rolling to the next file? I would name my logs by date, and would like the old files to compress (zip, cab, some format readable without extra installs) as a new file is being created. Also, is it possible to have a max number of files saved? We would like to only keep the last x days of logs. So day to day the files would be compressed and after x days, the compressed files would be removed. Is this possible currently, or planned in the future? Mike
Re: Compress Delete old log
Thanks for the reply... appender name=RollingFile type=log4net.Appender.RollingFileAppender file value=C:\Projects\IaDoc\Icon\log\web.log / appendToFile value=true / maximumFileSize value=100MB / maxSizeRollBackups value=-1 / layout type=log4net.Layout.PatternLayout conversionPattern value=%5level [%date] [%thread] %-30.30logger{2}%message%newline / /layout /appender In my case at least I would like it to write a 100mb file, create a new one to log to, and then compress the original file in a separate thread to that dates zip file. For example lets say that my application logs 500mb a day. When reaching the 100mb limit it would rename the file to web.log.date as it does today and create a new web.log. It would then create a new thread that would move that log file to a zip archive web.log.date.zip. When the limit is reached again, the same thing would happen only web.log.date-x file that is created would be moved into the existing web.log.date.zip file. Also the MaxSizeRollBackups is per time based group. (The maximum applies to each time based group of files and not the total.) We don't set a time, so it defaults to 1 day. We have that setting set to -1 so that we don't delete any for that day. I would like a setting that does it per appender so I can keep only the last 14 days worth of files. This request is so we don't need to have an external process to clean the logs. It is our policy that the one that does the logging, cleans up the logging. Thoughts? On 5/30/06, Ron Grabowski [EMAIL PROTECTED] wrote: The RollingFileAppender does not have compression support built-in. What should happen if I set my rolling log file size to 200mb? Should my application stop responding until the compression process is complete? According to this page: http://tinyurl.com/q48hv http://logging.apache.org/log4net/release/sdk/log4net.Appender.RollingFileAppender.MaxSizeRollBackups.html The MaxSizeRollBackups property is the maximum number of backup files that are kept before the oldest is erased. Are you able to roll files on a daily basis then run another program every day to compress old log files? There may be general purpose command line utilities that do this already. --- Michael Schall [EMAIL PROTECTED] wrote: Is there a way with the rollingfile appender to have it compress itself as it is rolling to the next file? I would name my logs by date, and would like the old files to compress (zip, cab, some format readable without extra installs) as a new file is being created. Also, is it possible to have a max number of files saved? We would like to only keep the last x days of logs. So day to day the files would be compressed and after x days, the compressed files would be removed. Is this possible currently, or planned in the future? Mike