Hi, ALL
Find that if the rolling file path do not exist, the appender will do
nothing (you will get confused what is wrong......)
I think it had better create the corresponding directory and file.
So I change the code at Log4net--Appender--FileAppender.cs
public override Stream AcquireLock()
{
if (m_stream==null)
{
try
{
using(CurrentAppender.SecurityContext.Impersonate(this))
{
// Ensure that the directory structure exists
string directoryFullName =
Path.GetDirectoryName(m_filename);
// Only create the directory if it does not
exist
// doing this check here resolves some
permissions failures
if (!Directory.Exists(directoryFullName))
{
Directory.CreateDirectory(directoryFullName);
}
//*added by me*
if (!System.IO.File.Exists(m_filename))
{
System.IO.File.Create(m_filename).Close();
}
FileMode fileOpenMode = m_append ?
FileMode.Append : FileMode.Create;
m_stream = new FileStream(m_filename,
fileOpenMode, FileAccess.Write, FileShare.Read);
m_append=true;
}
}
catch (Exception e1)
{
CurrentAppender.ErrorHandler.Error("Unable to
acquire lock on file "+m_filename+". "+e1.Message);
}
}
return m_stream;
}
The benefit is that anyone who uses log4net will feel convenient