You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-dev@logging.apache.org by "Ron Grabowski (JIRA)" <ji...@apache.org> on 2006/03/02 05:41:51 UTC

[jira] Commented: (LOG4NET-66) PreserveFileExtension with StaticFileName

    [ http://issues.apache.org/jira/browse/LOG4NET-66?page=comments#action_12368446 ] 

Ron Grabowski commented on LOG4NET-66:
--------------------------------------

I don't like the idea of using a regular expression to match filenames:

 "^" + Path.GetFileNameWithoutExtension(baseFileName) + "(\\.[0-9]*)?\\" + Path.GetExtension(baseFileName) + "$"

Wouldn't these filenames cause the regular expression to misbehave (square brackets, parenthesis, and the period have special meaning in regular expressions)?

 log[2.0].txt
 log[2.0].txt.1
 log[2.0].txt.2
 log(1.1).txt
 log(1.1).txt.1
 log(1.1).txt.2
 log(1.1).txt.3

I suppose writing another helper method would solve the problem:

 RegexEncode(Path.GetFileNameWithoutExtension(baseFileName))

Is there a way to use DirectoryInfo's GetFiles style searching (DOS wildcards) to achieve the same result?

> PreserveFileExtension with StaticFileName
> -----------------------------------------
>
>          Key: LOG4NET-66
>          URL: http://issues.apache.org/jira/browse/LOG4NET-66
>      Project: Log4net
>         Type: Improvement
>   Components: Appenders
>     Versions: 1.2.10
>  Environment: Windows Server 2003
>     Reporter: Mike Blake-Knox
>     Priority: Minor
>  Attachments: rollingFileAppender.diff
>
> I found that the patch to make all RollingFileAppender log files have the same file extension (provided by Joshua Bassett) didn't work properly if the log4net configuration used a static file name.
> I've attached a patch to version 312319 with his changes and mine merged.
> Mike

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


Re: [jira] Commented: (LOG4NET-66) PreserveFileExtension with StaticFileName

Posted by Mike Blake-Knox <mi...@gmail.com>.
On 3/21/06, josh robb <jo...@fastmail.fm> wrote:
> Uh - at the risk of mentioning something that everyone already knows:
>
> >  RegexEncode(Path.GetFileNameWithoutExtension(baseFileName))
>
> Regex.Escape(string str)
>
> Could be what you are looking for.
>

Absolutely true but not needed as the special chars bothering Ron were
in the input string (where any character can occur) and not in the
pattern (where you need to escape special characters).

In any event, I removed the regular expression code as it really did
feel like overkill.

--
Mike Blake-Knox

Re: [jira] Commented: (LOG4NET-66) PreserveFileExtension with StaticFileName

Posted by josh robb <jo...@fastmail.fm>.
Uh - at the risk of mentioning something that everyone already knows:

>  RegexEncode(Path.GetFileNameWithoutExtension(baseFileName))

Regex.Escape(string str)

Could be what you are looking for.

Re: [jira] Commented: (LOG4NET-66) PreserveFileExtension with StaticFileName

Posted by Mike Blake-Knox <mi...@gmail.com>.
On 3/1/06, Ron Grabowski (JIRA) <ji...@apache.org> wrote:
>     [ http://issues.apache.org/jira/browse/LOG4NET-66?page=comments#action_12368446 ]
>
> Ron Grabowski commented on LOG4NET-66:
> --------------------------------------
>
> I don't like the idea of using a regular expression to match filenames:

It is a bit heavy handed anyway.

I've removed the regular expression related code and attached an
updated diff to the JIRA issue.

>  "^" + Path.GetFileNameWithoutExtension(baseFileName) + "(\\.[0-9]*)?\\" + Path.GetExtension(baseFileName) + "$"
>
> Wouldn't these filenames cause the regular expression to misbehave (square brackets, parenthesis, and the period have special meaning in regular expressions)?

Regular expressions allow you to match against source text including
its special characters by prefixing the special character in the
pattern with a back-slash.

>
>  log[2.0].txt
>  log[2.0].txt.1
>  log[2.0].txt.2
>  log(1.1).txt
>  log(1.1).txt.1
>  log(1.1).txt.2
>  log(1.1).txt.3
>

Filenames with numeric extensions should never be generated when
preserveFileNameExtension is used. Maybe it needs warning text (like
that for staticFileName) highlighting that strange things need to
happen if you don't clear the directory first.

> I suppose writing another helper method would solve the problem:
>
>  RegexEncode(Path.GetFileNameWithoutExtension(baseFileName))
>
> Is there a way to use DirectoryInfo's GetFiles style searching (DOS wildcards) to achieve the same result?

Not that I've thought of.

What would have been better is to explicitly specify the extension to
be used and to remove the extension from the base filename. This would
probably fit in somewhat better with the original (non-extension
preserving code) and might even reduce overhead.

--
Mike Blake-Knox