You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Ralph Goers (Jira)" <ji...@apache.org> on 2020/04/04 22:30:04 UTC

[jira] [Updated] (LOG4NET-425) RollingFileAppender create log file without BOM if log file was deleted runtime

     [ https://issues.apache.org/jira/browse/LOG4NET-425?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Ralph Goers updated LOG4NET-425:
--------------------------------

LOG4NET is now dormant.  

> 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.11, 1.2.12, 1.2.13
>         Environment: Windows 7 x64, .NET 4
>            Reporter: eryw456f2345t
>            Priority: Minor
>
> RollingFileAppender create log file without Unicode Byte Order Mark 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
(v8.3.4#803005)