:alembic: provide "proper" namespacing on netstandard only, reverting to `log4net:event` and similar for .net framework
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 @@
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 @@
{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 @@
set {m_base64Properties=value;}
}
-
#endregion Public Instance Properties
#region Implementation of IOptionHandler
@@ -199,7 +198,7 @@
m_elmLocation = m_prefix + ":" + ELM_LOCATION;
}
}
-
+
#endregion Implementation of IOptionHandler
#region Override implementation of XMLLayoutBase
@@ -217,7 +216,12 @@
/// </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 @@
}
// 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 @@
// 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 @@
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 @@
{
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 @@
}
// 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 @@
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 @@
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 @@
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 @@
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 @@
{
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);