logging-log4net-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "eryw456f2345t (JIRA)" <j...@apache.org>
Subject [jira] [Created] (LOG4NET-425) RollingFileAppender create log file without BOM if log file was deleted runtime
Date Thu, 27 Feb 2014 11:56:19 GMT
eryw456f2345t created LOG4NET-425:
-------------------------------------

             Summary: RollingFileAppender create log file without BOM if log file was deleted
runtime
                 Key: LOG4NET-425
                 URL: https://issues.apache.org/jira/browse/LOG4NET-425
             Project: Log4net
          Issue Type: Bug
          Components: Appenders
    Affects Versions: 1.2.13, 1.2.12, 1.2.11
         Environment: Windows 7 x64, .NET 4
            Reporter: eryw456f2345t
            Priority: Minor


RollingFileAppender create log file without BOM if log file was deleted runtime.
Example of program:
{code:CSharp}
using System;
using System.IO;
using log4net;
using log4net.Config;

namespace log4net_test
{
	public class Program
	{
		public static void Main(string[] args)
		{
			var log4net_config_file_path = Path.Combine(Environment.CurrentDirectory, "log.config");
			File.WriteAllText(log4net_config_file_path, Config);
			GlobalContext.Properties["logDir"] = Environment.CurrentDirectory;
			var log4net_config = new FileInfo(log4net_config_file_path);
			XmlConfigurator.ConfigureAndWatch(log4net_config);

			var log_file = new FileInfo(Path.Combine(Environment.CurrentDirectory, "log.log"));
			var log = LogManager.GetLogger(typeof(Program));
			log.InfoFormat("Сообщение {0}", 1); // log with Unicode BOM
			log_file.Delete(); // delete log
			log.InfoFormat("Сообщение {0}", 2); // log without Unicode BOM
		}

		private static string Config
		{
			get
			{
				return
					@"<?xml version=""1.0"" encoding=""utf-8"" ?>
<log4net>
	<appender name=""MainAppender"" type=""log4net.Appender.RollingFileAppender"">
		<file type=""log4net.Util.PatternString"" value=""%property{logDir}/log.log"" />
		<lockingModel type=""log4net.Appender.FileAppender+MinimalLock"" />
		<appendToFile value=""true"" />
		<encoding value=""utf-8"" />
		<rollingStyle value=""Size"" />
		<maxSizeRollBackups value=""10"" />
		<maximumFileSize value=""5MB"" />
		<PreserveLogFileNameExtension value=""true"" />
		<staticLogFileName value=""true"" />
		<layout type=""log4net.Layout.PatternLayout"">
			<conversionPattern value=""%date [%thread] %-5level %logger - %message%newline%exception#End%newline""
/>
		</layout>
	</appender>

	<root>
		<appender-ref ref=""MainAppender"" />
	</root>
</log4net>";
			}
		}
	}
}
{code}



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Mime
View raw message