nicko 2004/08/02 02:44:11
Modified: src/Layout XMLLayout.cs XmlLayoutSchemaLog4j.cs
Log:
Added support for GlobalProperties
Revision Changes Path
1.6 +36 -2 logging-log4net/src/Layout/XMLLayout.cs
Index: XMLLayout.cs
===================================================================
RCS file: /home/cvs/logging-log4net/src/Layout/XMLLayout.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XMLLayout.cs 30 Jul 2004 20:48:36 -0000 1.5
+++ XMLLayout.cs 2 Aug 2004 09:44:11 -0000 1.6
@@ -92,7 +92,7 @@
/// at the origin of the log statement will be output.
/// </para>
/// <para>
- /// If you are embedding this layout within an SMTPAppender
+ /// If you are embedding this layout within an SmtpAppender
/// then make sure to set the <b>LocationInfo</b> option of
that
/// appender as well.
/// </para>
@@ -156,6 +156,7 @@
m_elmNdc = m_prefix + ":" + ELM_NDC;
m_elmMdc = m_prefix + ":" + ELM_MDC;
m_elmProperties = m_prefix + ":" +
ELM_PROPERTIES;
+ m_elmGlobalProperties = m_prefix + ":" +
ELM_GLOBAL_PROPERTIES;
m_elmData = m_prefix + ":" + ELM_DATA;
m_elmException = m_prefix + ":" + ELM_EXCEPTION;
m_elmLocation = m_prefix + ":" + ELM_LOCATION;
@@ -212,7 +213,9 @@
foreach(System.Collections.DictionaryEntry
entry in loggingEvent.MappedContext)
{
writer.WriteStartElement(m_elmData);
- writer.WriteAttributeString(ATTR_NAME,
entry.Key.ToString());
+ writer.WriteAttributeString(ATTR_NAME,
(string)entry.Key);
+
+ // TODO Should use an ObjectRenderer to
convert to a string
writer.WriteAttributeString(ATTR_VALUE,
entry.Value.ToString());
writer.WriteEndElement();
}
@@ -230,6 +233,8 @@
{
writer.WriteStartElement(m_elmData);
writer.WriteAttributeString(ATTR_NAME, key);
+
+ // TODO Should use an
ObjectRenderer to convert to a string
writer.WriteAttributeString(ATTR_VALUE,
loggingEvent.Properties[key].ToString());
writer.WriteEndElement();
}
@@ -237,6 +242,33 @@
}
}
+ if (loggingEvent.GlobalProperties != null)
+ {
+ // Append the properties text
+ string[] propKeys =
loggingEvent.Properties.GetKeys();
+ if (loggingEvent.GlobalProperties.Count > 0)
+ {
+
writer.WriteStartElement(m_elmGlobalProperties);
+
foreach(System.Collections.DictionaryEntry entry in
loggingEvent.GlobalProperties)
+ {
+
writer.WriteStartElement(m_elmData);
+
writer.WriteAttributeString(ATTR_NAME, (string)entry.Key);
+
+ if (entry.Value == null)
+ {
+
writer.WriteAttributeString(ATTR_VALUE, "null");
+ }
+ else
+ {
+ // TODO Should use an
ObjectRenderer to convert to a string
+
writer.WriteAttributeString(ATTR_VALUE, entry.Value.ToString());
+ }
+ writer.WriteEndElement();
+ }
+ writer.WriteEndElement();
+ }
+ }
+
string exceptionStr = loggingEvent.GetExceptionString();
if (exceptionStr != null && exceptionStr.Length > 0)
{
@@ -276,6 +308,7 @@
private string m_elmMdc = ELM_MDC;
private string m_elmData = ELM_DATA;
private string m_elmProperties = ELM_PROPERTIES;
+ private string m_elmGlobalProperties = ELM_GLOBAL_PROPERTIES;
private string m_elmException = ELM_EXCEPTION;
private string m_elmLocation = ELM_LOCATION;
@@ -290,6 +323,7 @@
private const string ELM_NDC = "ndc";
private const string ELM_MDC = "mdc";
private const string ELM_PROPERTIES = "properties";
+ private const string ELM_GLOBAL_PROPERTIES =
"global-properties";
private const string ELM_DATA = "data";
private const string ELM_EXCEPTION = "exception";
private const string ELM_LOCATION = "locationInfo";
1.5 +14 -1 logging-log4net/src/Layout/XmlLayoutSchemaLog4j.cs
Index: XmlLayoutSchemaLog4j.cs
===================================================================
RCS file: /home/cvs/logging-log4net/src/Layout/XmlLayoutSchemaLog4j.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- XmlLayoutSchemaLog4j.cs 30 May 2004 11:10:07 -0000 1.4
+++ XmlLayoutSchemaLog4j.cs 2 Aug 2004 09:44:11 -0000 1.5
@@ -129,6 +129,15 @@
{
// Translate logging events for log4j
+ // Copy global properties
+ if (loggingEvent.GlobalProperties != null)
+ {
+ foreach(System.Collections.DictionaryEntry
entry in loggingEvent.GlobalProperties)
+ {
+
loggingEvent.Properties[(string)entry.Key] = entry.Value;
+ }
+ }
+
// Translate hostname property
if
(loggingEvent.Properties[LoggingEvent.HostNameProperty] != null &&
loggingEvent.Properties["log4jmachinename"] ==
null)
@@ -190,7 +199,9 @@
foreach(System.Collections.DictionaryEntry
entry in loggingEvent.MappedContext)
{
writer.WriteStartElement("log4j:data");
- writer.WriteAttributeString("name",
entry.Key.ToString());
+ writer.WriteAttributeString("name",
(string)entry.Key);
+
+ // TODO: Use an ObjectRenderer to
convert the object to a string
writer.WriteAttributeString("value",
entry.Value.ToString());
writer.WriteEndElement();
}
@@ -208,6 +219,8 @@
{
writer.WriteStartElement("log4j:data");
writer.WriteAttributeString("name", key);
+
+ // TODO: Use an ObjectRenderer
to convert the object to a string
writer.WriteAttributeString("value", loggingEvent.Properties[key].ToString());
writer.WriteEndElement();
}