You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by da...@apache.org on 2022/01/24 08:12:34 UTC
[logging-log4net] branch master updated (e817e2a -> 54ca7c3)
This is an automated email from the ASF dual-hosted git repository.
davydm pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git.
from e817e2a :bug: :memo: should mention 2.0.14, not 2.0.13
new acc55ec :fire: remove dead commented code
new 54ca7c3 :alembic: provide "proper" namespacing on netstandard only, reverting to `log4net:event` and similar for .net framework
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
src/integration-testing/log4net-672/Program.cs | 102 ++++++++++++++++++++
.../log4net-672/log4net-672.csproj | 23 +++++
src/integration-testing/log4net-672/log4net.config | 18 ++++
src/log4net.sln | 13 +++
src/log4net/Layout/XmlLayout.cs | 28 +++++-
src/log4net/Layout/XmlLayoutSchemaLog4j.cs | 28 ++++++
src/log4net/Util/OptionConverter.cs | 103 ---------------------
7 files changed, 210 insertions(+), 105 deletions(-)
create mode 100644 src/integration-testing/log4net-672/Program.cs
create mode 100644 src/integration-testing/log4net-672/log4net-672.csproj
create mode 100644 src/integration-testing/log4net-672/log4net.config
[logging-log4net] 01/02: :fire: remove dead commented code
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davydm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git
commit acc55ec1754824e385ad2812d936ecd43407e6e2
Author: Davyd McColl <da...@gmail.com>
AuthorDate: Fri Jan 21 15:18:23 2022 +0200
:fire: remove dead commented code
---
src/log4net/Util/OptionConverter.cs | 103 ------------------------------------
1 file changed, 103 deletions(-)
diff --git a/src/log4net/Util/OptionConverter.cs b/src/log4net/Util/OptionConverter.cs
index 776bcc2..21eabfe 100644
--- a/src/log4net/Util/OptionConverter.cs
+++ b/src/log4net/Util/OptionConverter.cs
@@ -18,7 +18,6 @@
#endregion
using System;
-using System.Collections;
using System.Globalization;
using System.Reflection;
using System.Text;
@@ -58,79 +57,6 @@ namespace log4net.Util
#region Public Static Methods
-// /// <summary>
-// /// Concatenates two string arrays.
-// /// </summary>
-// /// <param name="l">Left array.</param>
-// /// <param name="r">Right array.</param>
-// /// <returns>Array containing both left and right arrays.</returns>
-// public static string[] ConcatenateArrays(string[] l, string[] r)
-// {
-// return (string[])ConcatenateArrays(l, r);
-// }
-
-// /// <summary>
-// /// Concatenates two arrays.
-// /// </summary>
-// /// <param name="l">Left array</param>
-// /// <param name="r">Right array</param>
-// /// <returns>Array containing both left and right arrays.</returns>
-// public static Array ConcatenateArrays(Array l, Array r)
-// {
-// if (l == null)
-// {
-// throw new ArgumentNullException("l");
-// }
-// if (r == null)
-// {
-// throw new ArgumentNullException("r");
-// }
-//
-// int len = l.Length + r.Length;
-// Array a = Array.CreateInstance(l.GetType(), len);
-//
-// Array.Copy(l, 0, a, 0, l.Length);
-// Array.Copy(r, 0, a, l.Length, r.Length);
-//
-// return a;
-// }
-
-// /// <summary>
-// /// Converts string escape characters back to their correct values.
-// /// </summary>
-// /// <param name="s">String to convert.</param>
-// /// <returns>Converted result.</returns>
-// public static string ConvertSpecialChars(string s)
-// {
-// if (s == null)
-// {
-// throw new ArgumentNullException("s");
-// }
-// char c;
-// int len = s.Length;
-// StringBuilder buf = new StringBuilder(len);
-//
-// int i = 0;
-// while(i < len)
-// {
-// c = s[i++];
-// if (c == '\\')
-// {
-// c = s[i++];
-// if (c == 'n') c = '\n';
-// else if (c == 'r') c = '\r';
-// else if (c == 't') c = '\t';
-// else if (c == 'f') c = '\f';
-// else if (c == '\b') c = '\b';
-// else if (c == '\"') c = '\"';
-// else if (c == '\'') c = '\'';
-// else if (c == '\\') c = '\\';
-// }
-// buf.Append(c);
-// }
-// return buf.ToString();
-// }
-
/// <summary>
/// Converts a string to a <see cref="bool" /> value.
/// </summary>
@@ -160,35 +86,6 @@ namespace log4net.Util
return defaultValue;
}
-// /// <summary>
-// /// Converts a string to an integer.
-// /// </summary>
-// /// <param name="argValue">String to convert.</param>
-// /// <param name="defaultValue">The default value.</param>
-// /// <returns>The <see cref="int" /> value of <paramref name="argValue" />.</returns>
-// /// <remarks>
-// /// <para>
-// /// <paramref name="defaultValue"/> is returned when <paramref name="argValue"/>
-// /// cannot be converted to a <see cref="int" /> value.
-// /// </para>
-// /// </remarks>
-// public static int ToInt(string argValue, int defaultValue)
-// {
-// if (argValue != null)
-// {
-// string s = argValue.Trim();
-// try
-// {
-// return int.Parse(s, NumberFormatInfo.InvariantInfo);
-// }
-// catch (Exception e)
-// {
-// LogLog.Error(declaringType, "OptionConverter: [" + s + "] is not in proper int form.", e);
-// }
-// }
-// return defaultValue;
-// }
-
/// <summary>
/// Parses a file size into a number.
/// </summary>
[logging-log4net] 02/02: :alembic: provide "proper" namespacing on netstandard only, reverting to `log4net:event` and similar for .net framework
Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
davydm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4net.git
commit 54ca7c355e6de708014d36303e29bb4e6a172a90
Author: Davyd McColl <da...@gmail.com>
AuthorDate: Mon Jan 24 10:11:34 2022 +0200
:alembic: provide "proper" namespacing on netstandard only, reverting to `log4net:event` and similar for .net framework
---
src/integration-testing/log4net-672/Program.cs | 102 +++++++++++++++++++++
.../log4net-672/log4net-672.csproj | 23 +++++
src/integration-testing/log4net-672/log4net.config | 18 ++++
src/log4net.sln | 13 +++
src/log4net/Layout/XmlLayout.cs | 28 +++++-
src/log4net/Layout/XmlLayoutSchemaLog4j.cs | 28 ++++++
6 files changed, 210 insertions(+), 2 deletions(-)
diff --git a/src/integration-testing/log4net-672/Program.cs b/src/integration-testing/log4net-672/Program.cs
new file mode 100644
index 0000000..64be479
--- /dev/null
+++ b/src/integration-testing/log4net-672/Program.cs
@@ -0,0 +1,102 @@
+using System;
+using System.IO;
+using System.Reflection;
+using System.Xml;
+using log4net;
+using log4net.Config;
+using log4net.Core;
+
+if (true)
+{
+ var appPath = new Uri(Assembly.GetExecutingAssembly().Location).LocalPath;
+ var appFolder = Path.GetDirectoryName(appPath);
+ if (appFolder is null)
+ {
+ throw new InvalidOperationException(
+ $"Can't determine app folder for {appPath}"
+ );
+ }
+
+ var configFile = Path.Combine(appFolder, "log4net.config");
+ if (!File.Exists(configFile))
+ {
+ throw new InvalidOperationException($"log4net.config not found at {configFile}");
+ }
+
+ var info = new FileInfo(configFile);
+
+ XmlConfigurator.Configure(info);
+
+ var logger = LogManager.GetLogger("main");
+
+ for (var i = 0; i < 10; i++)
+ {
+ logger.Info($"test log {i}");
+ }
+
+ LogManager.Flush(int.MaxValue);
+}
+
+// Sample.Main();
+//
+// public class Sample
+// {
+// private const string filename = "sampledata.xml";
+//
+// public static void Main()
+// {
+//
+// XmlTextWriter writer = new XmlTextWriter (filename, null);
+// //Use indenting for readability.
+// writer.Formatting = Formatting.Indented;
+//
+// writer.WriteComment("sample XML fragment");
+//
+// //Write an element (this one is the root).
+// writer.WriteStartElement("bookstore");
+//
+// //Write the namespace declaration.
+// writer.WriteAttributeString("xmlns", "bk", null, "log4net");
+//
+// writer.WriteStartElement("book");
+//
+// //Lookup the prefix and then write the ISBN attribute.
+// string prefix = writer.LookupPrefix("urn:samples");
+// writer.WriteStartAttribute(prefix, "ISBN", "urn:samples");
+// writer.WriteString("1-861003-78");
+// writer.WriteEndAttribute();
+//
+// //Write the title.
+// writer.WriteStartElement("title");
+// writer.WriteString("The Handmaid's Tale");
+// writer.WriteEndElement();
+//
+// //Write the price.
+// writer.WriteElementString("price", "19.95");
+//
+// //Write the style element.
+// writer.WriteStartElement(prefix, "style", "urn:samples");
+// writer.WriteString("hardcover");
+// writer.WriteEndElement();
+//
+// //Write the end tag for the book element.
+// writer.WriteEndElement();
+//
+// //Write the close tag for the root element.
+// writer.WriteEndElement();
+//
+// //Write the XML to file and close the writer.
+// writer.Flush();
+// writer.Close();
+//
+// //Read the file back in and parse to ensure well formed XML.
+// XmlDocument doc = new XmlDocument();
+// //Preserve white space for readability.
+// doc.PreserveWhitespace = true;
+// //Load the file
+// doc.Load(filename);
+//
+// //Write the XML content to the console.
+// Console.Write(doc.InnerXml);
+// }
+// }
diff --git a/src/integration-testing/log4net-672/log4net-672.csproj b/src/integration-testing/log4net-672/log4net-672.csproj
new file mode 100644
index 0000000..e0ac350
--- /dev/null
+++ b/src/integration-testing/log4net-672/log4net-672.csproj
@@ -0,0 +1,23 @@
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <OutputType>Exe</OutputType>
+ <TargetFramework>net6.0</TargetFramework>
+ <RootNamespace>log4net_672</RootNamespace>
+ <ImplicitUsings>disable</ImplicitUsings>
+ <Nullable>enable</Nullable>
+ <LangVersion>preview</LangVersion>
+ <DefineConstants>NETSTANDARD</DefineConstants>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="..\..\log4net\log4net.csproj" />
+ </ItemGroup>
+
+ <ItemGroup>
+ <None Update="log4net.config">
+ <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ </None>
+ </ItemGroup>
+
+</Project>
diff --git a/src/integration-testing/log4net-672/log4net.config b/src/integration-testing/log4net-672/log4net.config
new file mode 100644
index 0000000..0e685d6
--- /dev/null
+++ b/src/integration-testing/log4net-672/log4net.config
@@ -0,0 +1,18 @@
+<log4net>
+ <appender name="LogFileAppenderXML" type="log4net.Appender.RollingFileAppender">
+ <file value="Logs\.xml" />
+ <datePattern value="yyyy-MM-dd-'Xyz'" />
+ <appendToFile value="true" />
+ <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
+ <rollingStyle value="Composite" />
+ <maxSizeRollBackups value="40" />
+ <maximumFileSize value="1KB" />
+ <preserveLogFileNameExtension value="true" />
+ <staticLogFileName value="false" />
+ <layout type="log4net.Layout.XmlLayout"/>
+ </appender>
+ <root>
+ <level value="ALL"/>
+ <appender-ref ref="LogFileAppenderXML" />
+ </root>
+</log4net>
\ No newline at end of file
diff --git a/src/log4net.sln b/src/log4net.sln
index c08c55c..ae6d168 100644
--- a/src/log4net.sln
+++ b/src/log4net.sln
@@ -24,6 +24,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net", "log4net\log4net.
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net.Tests", "log4net.Tests\log4net.Tests.csproj", "{B0530F10-0238-49A9-93B0-8EF412E90BCF}"
EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "integration-testing", "integration-testing", "{8953473C-EEE8-4740-993D-B8E10FA876CD}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "log4net-672", "integration-testing\log4net-672\log4net-672.csproj", "{9050922E-E22E-4FF5-A1B0-2F21745C6882}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -43,8 +47,17 @@ Global
{B0530F10-0238-49A9-93B0-8EF412E90BCF}.Release|Any CPU.Build.0 = Release|Any CPU
{B0530F10-0238-49A9-93B0-8EF412E90BCF}.CrossPlatform|Any CPU.ActiveCfg = CrossPlatform|Any CPU
{B0530F10-0238-49A9-93B0-8EF412E90BCF}.CrossPlatform|Any CPU.Build.0 = CrossPlatform|Any CPU
+ {9050922E-E22E-4FF5-A1B0-2F21745C6882}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9050922E-E22E-4FF5-A1B0-2F21745C6882}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9050922E-E22E-4FF5-A1B0-2F21745C6882}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9050922E-E22E-4FF5-A1B0-2F21745C6882}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9050922E-E22E-4FF5-A1B0-2F21745C6882}.CrossPlatform|Any CPU.ActiveCfg = Debug|Any CPU
+ {9050922E-E22E-4FF5-A1B0-2F21745C6882}.CrossPlatform|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(NestedProjects) = preSolution
+ {9050922E-E22E-4FF5-A1B0-2F21745C6882} = {8953473C-EEE8-4740-993D-B8E10FA876CD}
+ EndGlobalSection
EndGlobal
diff --git a/src/log4net/Layout/XmlLayout.cs b/src/log4net/Layout/XmlLayout.cs
index 66b7dcf..7c5c0c2 100644
--- a/src/log4net/Layout/XmlLayout.cs
+++ b/src/log4net/Layout/XmlLayout.cs
@@ -160,7 +160,6 @@ namespace log4net.Layout
set {m_base64Properties=value;}
}
-
#endregion Public Instance Properties
#region Implementation of IOptionHandler
@@ -199,7 +198,7 @@ namespace log4net.Layout
m_elmLocation = m_prefix + ":" + ELM_LOCATION;
}
}
-
+
#endregion Implementation of IOptionHandler
#region Override implementation of XMLLayoutBase
@@ -217,7 +216,12 @@ namespace log4net.Layout
/// </remarks>
protected override void FormatXml(XmlWriter writer, LoggingEvent loggingEvent)
{
+ #if NETSTANDARD
+ writer.WriteStartElement(m_prefix, ELM_EVENT, m_prefix);
+ // writer.WriteAttributeString("xmlns", "log4net", null, "http://logging.apache.org/log4net/schemas/log4net-events-1.2");
+ #else
writer.WriteStartElement(m_elmEvent);
+ #endif
writer.WriteAttributeString(ATTR_LOGGER, loggingEvent.LoggerName);
#if NET_2_0 || NETCF_2_0 || MONO_2_0 || NETSTANDARD
@@ -243,7 +247,11 @@ namespace log4net.Layout
}
// Append the message text
+ #if NETSTANDARD
+ writer.WriteStartElement(m_prefix, ELM_MESSAGE, m_prefix);
+ #else
writer.WriteStartElement(m_elmMessage);
+ #endif
if (!this.Base64EncodeMessage)
{
Transform.WriteEscapedXmlString(writer, loggingEvent.RenderedMessage, this.InvalidCharReplacement);
@@ -261,10 +269,18 @@ namespace log4net.Layout
// Append the properties text
if (properties.Count > 0)
{
+ #if NETSTANDARD
+ writer.WriteStartElement(m_prefix, ELM_PROPERTIES, m_prefix);
+ #else
writer.WriteStartElement(m_elmProperties);
+ #endif
foreach(System.Collections.DictionaryEntry entry in properties)
{
+ #if NETSTANDARD
+ writer.WriteStartElement(m_prefix, ELM_DATA, m_prefix);
+ #else
writer.WriteStartElement(m_elmData);
+ #endif
writer.WriteAttributeString(ATTR_NAME, Transform.MaskXmlInvalidCharacters((string)entry.Key,this.InvalidCharReplacement));
// Use an ObjectRenderer to convert the object to a string
@@ -289,7 +305,11 @@ namespace log4net.Layout
if (exceptionStr != null && exceptionStr.Length > 0)
{
// Append the stack trace line
+ #if NETSTANDARD
+ writer.WriteStartElement(m_prefix, ELM_EXCEPTION, m_prefix);
+ #else
writer.WriteStartElement(m_elmException);
+ #endif
Transform.WriteEscapedXmlString(writer, exceptionStr,this.InvalidCharReplacement);
writer.WriteEndElement();
}
@@ -298,7 +318,11 @@ namespace log4net.Layout
{
LocationInfo locationInfo = loggingEvent.LocationInformation;
+ #if NETSTANDARD
+ writer.WriteStartElement(m_prefix, ELM_LOCATION, m_prefix);
+ #else
writer.WriteStartElement(m_elmLocation);
+ #endif
writer.WriteAttributeString(ATTR_CLASS, locationInfo.ClassName);
writer.WriteAttributeString(ATTR_METHOD, locationInfo.MethodName);
writer.WriteAttributeString(ATTR_FILE, locationInfo.FileName);
diff --git a/src/log4net/Layout/XmlLayoutSchemaLog4j.cs b/src/log4net/Layout/XmlLayoutSchemaLog4j.cs
index 19dde79..d5ac73f 100644
--- a/src/log4net/Layout/XmlLayoutSchemaLog4j.cs
+++ b/src/log4net/Layout/XmlLayoutSchemaLog4j.cs
@@ -172,7 +172,11 @@ method="run" file="Generator.java" line="94"/>
}
// Write the start element
+ #if NETSTANDARD
writer.WriteStartElement("log4j", "event", "log4net");
+ #else
+ writer.WriteStartElement("log4j:event");
+ #endif
writer.WriteAttributeString("logger", loggingEvent.LoggerName);
// Calculate the timestamp as the number of milliseconds since january 1970
@@ -187,7 +191,11 @@ method="run" file="Generator.java" line="94"/>
writer.WriteAttributeString("thread", loggingEvent.ThreadName);
// Append the message text
+ #if NETSTANDARD
writer.WriteStartElement("log4j", "message", "log4net");
+ #else
+ writer.WriteStartElement("log4j:message");
+ #endif
Transform.WriteEscapedXmlString(writer, loggingEvent.RenderedMessage,this.InvalidCharReplacement);
writer.WriteEndElement();
@@ -199,7 +207,11 @@ method="run" file="Generator.java" line="94"/>
if (valueStr != null && valueStr.Length > 0)
{
// Append the NDC text
+ #if NETSTANDARD
writer.WriteStartElement("log4j", "NDC", "log4net");
+ #else
+ writer.WriteStartElement("log4j:NDC");
+ #endif
Transform.WriteEscapedXmlString(writer, valueStr,this.InvalidCharReplacement);
writer.WriteEndElement();
}
@@ -209,10 +221,18 @@ method="run" file="Generator.java" line="94"/>
PropertiesDictionary properties = loggingEvent.GetProperties();
if (properties.Count > 0)
{
+ #if NETSTANDARD
writer.WriteStartElement("log4j", "properties", "log4net");
+ #else
+ writer.WriteStartElement("log4j:properties");
+ #endif
foreach(System.Collections.DictionaryEntry entry in properties)
{
+ #if NETSTANDARD
writer.WriteStartElement("log4j", "data", "log4net");
+ #else
+ writer.WriteStartElement("log4j:data");
+ #endif
writer.WriteAttributeString("name", (string)entry.Key);
// Use an ObjectRenderer to convert the object to a string
@@ -228,7 +248,11 @@ method="run" file="Generator.java" line="94"/>
if (exceptionStr != null && exceptionStr.Length > 0)
{
// Append the stack trace line
+ #if NETSTANDARD
writer.WriteStartElement("log4j", "throwable", "log4net");
+ #else
+ writer.WriteStartElement("log4j:throwable");
+ #endif
Transform.WriteEscapedXmlString(writer, exceptionStr,this.InvalidCharReplacement);
writer.WriteEndElement();
}
@@ -237,7 +261,11 @@ method="run" file="Generator.java" line="94"/>
{
LocationInfo locationInfo = loggingEvent.LocationInformation;
+ #if NETSTANDARD
writer.WriteStartElement("log4j", "locationInfo", "log4net");
+ #else
+ writer.WriteStartElement("log4j:locationInfo");
+ #endif
writer.WriteAttributeString("class", locationInfo.ClassName);
writer.WriteAttributeString("method", locationInfo.MethodName);
writer.WriteAttributeString("file", locationInfo.FileName);