You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by "Chu, Greg" <Gr...@wendys.com> on 2013/06/12 15:44:33 UTC

Log file availability issue

During the application running the log file is locked. I am trying to email the log file inside the application while the application is running.
Do I have any way to close the log file so it is unlocked, so that I can get the log file and email it?

Thanks

Greg

Notice: This e-mail message and its attachments are the property of The Wendy's Company or one of its subsidiaries and may contain confidential or legally privileged information intended solely for the use of the addressee(s). If you are not an intended recipient, then any use, copying or distribution of this message or its attachments is strictly prohibited. If you received this message in error, please notify the sender and delete this message entirely from your system.

Re: Log file availability issue

Posted by Ivan Habunek <iv...@gmail.com>.
I am a total idiot. Just noticed this came to the log4net list, not
log4php... :D

Sorry guys.

Regards,
Ivan


On 13 June 2013 01:25, Ron Grabowski <ro...@yahoo.com> wrote:

> You can use a minimal lock on your FileAppender:
>
>
> <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
>
>
> but it'll slow things down because it will open and close the file with
> each write. I've used code like this before to open a locked file:
>
> // from http://www.ericbt.com/Blog/48
> using (FileStream fileStream = new FileStream(path, FileMode.Open,
> FileAccess.Read, FileShare.ReadWrite))
> {
>   using (StreamReader streamReader = new StreamReader(fileStream))
>   {
>     logFileText = streamReader.ReadToEnd();
>   }
> }
>
>   ------------------------------
>  *From:* "Chu, Greg" <Gr...@wendys.com>
> *To:* "log4net-user@logging.apache.org" <lo...@logging.apache.org>
> *Sent:* Wednesday, June 12, 2013 9:44 AM
> *Subject:* Log file availability issue
>
>  During the application running the log file is locked. I am trying to
> email the log file inside the application while the application is running.
> Do I have any way to close the log file so it is unlocked, so that I can
> get the log file and email it?
>
> Thanks
>
> Greg
>
>  Notice: This e-mail message and its attachments are the property of The
> Wendy's Company or one of its subsidiaries and may contain confidential or
> legally privileged information intended solely for the use of the
> addressee(s). If you are not an intended recipient, then any use, copying
> or distribution of this message or its attachments is strictly prohibited.
> If you received this message in error, please notify the sender and delete
> this message entirely from your system.
>
>
>

Re: Log file availability issue

Posted by Ron Grabowski <ro...@yahoo.com>.
You can use a minimal lock on your FileAppender:

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

but it'll slow things down because it will open and close the file with each write. I've used code like this before to open a locked file:

// from http://www.ericbt.com/Blog/48
using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
  using (StreamReader streamReader = new StreamReader(fileStream))
  {
    logFileText = streamReader.ReadToEnd();
  }
}


________________________________
 From: "Chu, Greg" <Gr...@wendys.com>
To: "log4net-user@logging.apache.org" <lo...@logging.apache.org> 
Sent: Wednesday, June 12, 2013 9:44 AM
Subject: Log file availability issue
 


 
During the application running the log file is locked. I am trying to email the log file inside the application while the application is running.
Do I have any way to close the log file so it is unlocked, so that I can get the log file and email it?
 
Thanks
 
Greg
 
Notice: This e-mail message and its attachments are the property of The Wendy's Company or one of its subsidiaries and may contain confidential or legally privileged information intended solely for the use of the addressee(s). If you are not an intended recipient, then any use, copying or distribution of this message or its attachments is strictly prohibited. If you received this message in error, please notify the sender and delete this message entirely from your system. 

Re: Log file availability issue

Posted by Ivan Habunek <iv...@gmail.com>.
Hi Greg,

You should be able to read the file while the program is running. Check out
this quick example:
https://gist.github.com/ihabunek/5765463

It's reading the file contents while logging to it in.

The appender acquires a lock before writing to the file, but releases it
after writing. The log file should not be locked.

Now, I don't know how you're accessing the file, or how you're sending it
via email. Maybe you can send me a code snippet which demonstrates your
problem?

Best regards,
Ivan



On 12 June 2013 15:44, Chu, Greg <Gr...@wendys.com> wrote:

>  During the application running the log file is locked. I am trying to
> email the log file inside the application while the application is running.
>
> Do I have any way to close the log file so it is unlocked, so that I can
> get the log file and email it?
>
>
>
> Thanks
>
>
>
> Greg
>
>
>  Notice: This e-mail message and its attachments are the property of The
> Wendy's Company or one of its subsidiaries and may contain confidential or
> legally privileged information intended solely for the use of the
> addressee(s). If you are not an intended recipient, then any use, copying
> or distribution of this message or its attachments is strictly prohibited.
> If you received this message in error, please notify the sender and delete
> this message entirely from your system.
>