You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by AdamTappis <ad...@hotmail.com> on 2009/08/17 15:12:29 UTC

Adding custom logging properties

Hi,

I've been evaluating log4net recently with a view to using the framework as
a loggin standard for our enterprise applicaption. I see it very easy to
extend the framework, however I have some specific logging requirements and
I'm not sure what would be the easiest way implement these with minimal
coding.

At some time in the future, we aim to build a consolidated logging database
that will capture logging data from our server application suite. The
information that needs to be logged will differ per service/applicaption and
to that end I would aim to have a table schema that has the standard logging
columns plus a generic XML column (no defined schema) to act as a property
bag for custom information associated with a specific event.

We don't have time to develop the logging repository at present, however I'm
stressing that we should build logging into our code from the start rather
than trying to retro-fitting it later which would be far more costly.

So I need my code to be able to fire off logging messages with a list or
arbitrary custom properties that get formatted into an XML string. For now
the messages can be written to a text file and later we'll configure and
AdoNetAppender to write to out logging database.

So my questions are:
- Is this possible using configuration only? (I susopect not)
- If not then which custom objects do I need to create? From what I've seen
so far I think I'll need to code my own Layout Class
- The ILog interface doesn't doesn't expose a method that takes a property
bag (or dictionary), but it appears that the LoggingEvent object does. Does
that mean I would have to make my logging calls using ILog.Logger.Log()?
- Could someone provide some sample code please?
-- 
View this message in context: http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


RE: Adding custom logging properties

Posted by Karim Bourouba <ka...@hotmail.com>.
I agree, I have always viewed log4net as an unobtrusive logging framework and heaping things onto it like this could present problems further down the line.


 



Date: Mon, 17 Aug 2009 14:22:22 -0500
Subject: Re: Adding custom logging properties
From: rosshinkley@gmail.com
To: log4net-user@logging.apache.org

At a glace, that looks reasonable to me.

The only thing I can think of is that if you have a lot of custom properties, your logging code will be somewhat obtrusive.  I'm not sure this avoidable, no matter how you approach this problem.

-Ross


On Mon, Aug 17, 2009 at 12:59 PM, AdamTappis <ad...@hotmail.com> wrote:


OK,

So far I've created the following 2 very simple classes which appear to give
me what I need:

   class EventPropertiesXMLLayout : XmlLayoutBase
   {
       protected override void FormatXml(XmlWriter writer, LoggingEvent
loggingEvent)
       {
           LogMessage lm = loggingEvent.MessageObject as LogMessage;
           if (lm != null)
           {
               writer.WriteStartElement("LogEntry");
               writer.WriteStartElement("Message");
               writer.WriteValue(lm.Message);
               writer.WriteEndElement();
               writer.WriteStartElement("Properties");
               foreach (DictionaryEntry de in lm.Properties)
               {
                   writer.WriteStartElement(de.Key.ToString());
                   writer.WriteValue(de.Value.ToString());
                   writer.WriteEndElement();
               }
               writer.WriteEndElement();
               writer.WriteEndElement();
           }
       }
   }

   class LogMessage
   {
       private string _message;
       private Hashtable _properties;

       public LogMessage(string message)
       {
           _message = message;
           _properties = new Hashtable();
       }

       public string Message
       {
           get
           {
               return _message;
           }
       }

       public Hashtable Properties
       {
           get
           {
               return _properties;
           }
       }
   }

And then write the following code if I have to collect custom properties:

           LogMessage lm = new LogMessage("This is a custom log message");
           lm.Properties.Add("prop1", "value1");
           lm.Properties.Add("prop2", "value2");
           log.Info(lm);


Can you see any immediate issues or limitations with this approach?





AdamTappis wrote:
>
> How about if I create a custom LogMessage Class that has the message and
> distionary as properties and then write a cutom ObjectRenderer for my
> custom class. This would give my developers the flexibility of either
> logging strings or the custom LogMessage if they require additional
> properties. I guess what it doesn't give me is the flexibility or
> rendering the object to a file using one format and to a DB using a
> different formats. Objects of the specified type would always be rendered
> the same way.
>
>
> AdamTappis wrote:
>>
>> Having a closer look at the documentation, the Properties property of the
>> LoggingEvent class is a PropertiesDictionary which derives from
>> ReadOnlyPropertiesDictionary which menas it can't be written to and hence
>> it's not suitable for my purposes.
>>
>> Any ideas?
>>
>>
>> AdamTappis wrote:
>>>
>>> Ross,
>>>
>>> I guess that's why I'm posting here, because I'm trying to devise a
>>> pattern and some coding guidelines so that all our applications log
>>> consistently. I considered wrapping log4net but all I've read advises
>>> against that. So what I'm trying to achieve is an elegant solution that
>>> makes the best use of the framework.
>>>
>>> You're right, I wish to log a collection of Key-Value pairs associated
>>> with a given loggin event. e.g.
>>> statistics -
>>> <eventData><duration>3ms</duration><size>10kb</size></eventData>
>>> details -
>>> <eventData><customerID>3</customerID><orderID>10</orderID></eventData>
>>>
>>> The question I'm asking is how best to implement this with log4net?
>>>
>>> Should I write a wrapper or a helper class that accepts the key-Value
>>> pairs collection as a parameter and returns a formattred XML string that
>>> then get's logged?
>>>
>>> Maybe I should be creating a LoggingEvent in code manually, adding the
>>> Key-Value pairs to the Properties collection and then using
>>> ILog.Logger.Log to actually log the event rather than using Ilog.Info()
>>> to log. I could than write a custom layout class that serialises the
>>> properties out as an XML string.
>>>
>>> like I said, I'm not sure and am looking for some disrection.
>>>
>>> Ideally I would have the following interface available to me:
>>>
>>> ILog.Info(string message, Dictionary customProperties)
>>>
>>> and then it would be the configuration that drives how the
>>> customProperties are rendered by specifying the approporiate Layout
>>> class. That way I could format the customProperties to a file in one way
>>> and to a Db as XML etc... without embedding the formatting logic in my
>>> code.
>>>
>>>
>>> Ross Hinkley wrote:
>>>>
>>>> Adam,
>>>>
>>>> How are these properties getting transformed from a logging call to
>>>> XML?
>>>> Are you asking if there's a way to modify a custom format on the fly
>>>> and
>>>> then turn the custom properties into XML?  (I'm thinking of something
>>>> like
>>>> appending name-value pairs to the log format and having a custom
>>>> appender do
>>>> the XML conversion for you.  This doesn't seem terribly elegant.)
>>>>
>>>> Maybe I'm over-trivializing, but it seems to me you should be able to
>>>> use
>>>> custom properties to take care of your current needs, converting your
>>>> properties to XML in code, then modifying the ADO appender
>>>> configuration to
>>>> handle that property appropriately when the logging database is
>>>> implemented.
>>>>
>>>> I guess another question would be what sorts of things need to be
>>>> serialized?  Are they going to be serialized from a class?
>>>>
>>>> -Ross
>>>>
>>>> On Mon, Aug 17, 2009 at 8:12 AM, AdamTappis <ad...@hotmail.com>
>>>> wrote:
>>>>
>>>>>
>>>>> Hi,
>>>>>
>>>>> I've been evaluating log4net recently with a view to using the
>>>>> framework as
>>>>> a loggin standard for our enterprise applicaption. I see it very easy
>>>>> to
>>>>> extend the framework, however I have some specific logging
>>>>> requirements and
>>>>> I'm not sure what would be the easiest way implement these with
>>>>> minimal
>>>>> coding.
>>>>>
>>>>> At some time in the future, we aim to build a consolidated logging
>>>>> database
>>>>> that will capture logging data from our server application suite. The
>>>>> information that needs to be logged will differ per
>>>>> service/applicaption
>>>>> and
>>>>> to that end I would aim to have a table schema that has the standard
>>>>> logging
>>>>> columns plus a generic XML column (no defined schema) to act as a
>>>>> property
>>>>> bag for custom information associated with a specific event.
>>>>>
>>>>> We don't have time to develop the logging repository at present,
>>>>> however
>>>>> I'm
>>>>> stressing that we should build logging into our code from the start
>>>>> rather
>>>>> than trying to retro-fitting it later which would be far more costly.
>>>>>
>>>>> So I need my code to be able to fire off logging messages with a list
>>>>> or
>>>>> arbitrary custom properties that get formatted into an XML string. For
>>>>> now
>>>>> the messages can be written to a text file and later we'll configure
>>>>> and
>>>>> AdoNetAppender to write to out logging database.
>>>>>
>>>>> So my questions are:
>>>>> - Is this possible using configuration only? (I susopect not)
>>>>> - If not then which custom objects do I need to create? From what I've
>>>>> seen
>>>>> so far I think I'll need to code my own Layout Class
>>>>> - The ILog interface doesn't doesn't expose a method that takes a
>>>>> property
>>>>> bag (or dictionary), but it appears that the LoggingEvent object does.
>>>>> Does
>>>>> that mean I would have to make my logging calls using
>>>>> ILog.Logger.Log()?
>>>>> - Could someone provide some sample code please?
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
>>>>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>

--
View this message in context: http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25011405.html



Sent from the Log4net - Users mailing list archive at Nabble.com.



_________________________________________________________________
Windows Live Messenger: Celebrate 10 amazing years with free winks and emoticons.
http://clk.atdmt.com/UKM/go/157562755/direct/01/

Re: Adding custom logging properties

Posted by Ross Hinkley <ro...@gmail.com>.
At a glace, that looks reasonable to me.

The only thing I can think of is that if you have a lot of custom
properties, your logging code will be somewhat obtrusive.  I'm not sure this
avoidable, no matter how you approach this problem.

-Ross

On Mon, Aug 17, 2009 at 12:59 PM, AdamTappis <ad...@hotmail.com> wrote:

>
> OK,
>
> So far I've created the following 2 very simple classes which appear to
> give
> me what I need:
>
>    class EventPropertiesXMLLayout : XmlLayoutBase
>    {
>        protected override void FormatXml(XmlWriter writer, LoggingEvent
> loggingEvent)
>        {
>            LogMessage lm = loggingEvent.MessageObject as LogMessage;
>            if (lm != null)
>            {
>                writer.WriteStartElement("LogEntry");
>                writer.WriteStartElement("Message");
>                writer.WriteValue(lm.Message);
>                writer.WriteEndElement();
>                writer.WriteStartElement("Properties");
>                foreach (DictionaryEntry de in lm.Properties)
>                {
>                    writer.WriteStartElement(de.Key.ToString());
>                    writer.WriteValue(de.Value.ToString());
>                    writer.WriteEndElement();
>                }
>                writer.WriteEndElement();
>                writer.WriteEndElement();
>            }
>        }
>    }
>
>    class LogMessage
>    {
>        private string _message;
>        private Hashtable _properties;
>
>        public LogMessage(string message)
>        {
>            _message = message;
>            _properties = new Hashtable();
>        }
>
>        public string Message
>        {
>            get
>            {
>                return _message;
>            }
>        }
>
>        public Hashtable Properties
>        {
>            get
>            {
>                return _properties;
>            }
>        }
>    }
>
> And then write the following code if I have to collect custom properties:
>
>            LogMessage lm = new LogMessage("This is a custom log message");
>            lm.Properties.Add("prop1", "value1");
>            lm.Properties.Add("prop2", "value2");
>            log.Info(lm);
>
>
> Can you see any immediate issues or limitations with this approach?
>
>
> AdamTappis wrote:
> >
> > How about if I create a custom LogMessage Class that has the message and
> > distionary as properties and then write a cutom ObjectRenderer for my
> > custom class. This would give my developers the flexibility of either
> > logging strings or the custom LogMessage if they require additional
> > properties. I guess what it doesn't give me is the flexibility or
> > rendering the object to a file using one format and to a DB using a
> > different formats. Objects of the specified type would always be rendered
> > the same way.
> >
> >
> > AdamTappis wrote:
> >>
> >> Having a closer look at the documentation, the Properties property of
> the
> >> LoggingEvent class is a PropertiesDictionary which derives from
> >> ReadOnlyPropertiesDictionary which menas it can't be written to and
> hence
> >> it's not suitable for my purposes.
> >>
> >> Any ideas?
> >>
> >>
> >> AdamTappis wrote:
> >>>
> >>> Ross,
> >>>
> >>> I guess that's why I'm posting here, because I'm trying to devise a
> >>> pattern and some coding guidelines so that all our applications log
> >>> consistently. I considered wrapping log4net but all I've read advises
> >>> against that. So what I'm trying to achieve is an elegant solution that
> >>> makes the best use of the framework.
> >>>
> >>> You're right, I wish to log a collection of Key-Value pairs associated
> >>> with a given loggin event. e.g.
> >>> statistics -
> >>> <eventData><duration>3ms</duration><size>10kb</size></eventData>
> >>> details -
> >>> <eventData><customerID>3</customerID><orderID>10</orderID></eventData>
> >>>
> >>> The question I'm asking is how best to implement this with log4net?
> >>>
> >>> Should I write a wrapper or a helper class that accepts the key-Value
> >>> pairs collection as a parameter and returns a formattred XML string
> that
> >>> then get's logged?
> >>>
> >>> Maybe I should be creating a LoggingEvent in code manually, adding the
> >>> Key-Value pairs to the Properties collection and then using
> >>> ILog.Logger.Log to actually log the event rather than using Ilog.Info()
> >>> to log. I could than write a custom layout class that serialises the
> >>> properties out as an XML string.
> >>>
> >>> like I said, I'm not sure and am looking for some disrection.
> >>>
> >>> Ideally I would have the following interface available to me:
> >>>
> >>> ILog.Info(string message, Dictionary customProperties)
> >>>
> >>> and then it would be the configuration that drives how the
> >>> customProperties are rendered by specifying the approporiate Layout
> >>> class. That way I could format the customProperties to a file in one
> way
> >>> and to a Db as XML etc... without embedding the formatting logic in my
> >>> code.
> >>>
> >>>
> >>> Ross Hinkley wrote:
> >>>>
> >>>> Adam,
> >>>>
> >>>> How are these properties getting transformed from a logging call to
> >>>> XML?
> >>>> Are you asking if there's a way to modify a custom format on the fly
> >>>> and
> >>>> then turn the custom properties into XML?  (I'm thinking of something
> >>>> like
> >>>> appending name-value pairs to the log format and having a custom
> >>>> appender do
> >>>> the XML conversion for you.  This doesn't seem terribly elegant.)
> >>>>
> >>>> Maybe I'm over-trivializing, but it seems to me you should be able to
> >>>> use
> >>>> custom properties to take care of your current needs, converting your
> >>>> properties to XML in code, then modifying the ADO appender
> >>>> configuration to
> >>>> handle that property appropriately when the logging database is
> >>>> implemented.
> >>>>
> >>>> I guess another question would be what sorts of things need to be
> >>>> serialized?  Are they going to be serialized from a class?
> >>>>
> >>>> -Ross
> >>>>
> >>>> On Mon, Aug 17, 2009 at 8:12 AM, AdamTappis <ad...@hotmail.com>
> >>>> wrote:
> >>>>
> >>>>>
> >>>>> Hi,
> >>>>>
> >>>>> I've been evaluating log4net recently with a view to using the
> >>>>> framework as
> >>>>> a loggin standard for our enterprise applicaption. I see it very easy
> >>>>> to
> >>>>> extend the framework, however I have some specific logging
> >>>>> requirements and
> >>>>> I'm not sure what would be the easiest way implement these with
> >>>>> minimal
> >>>>> coding.
> >>>>>
> >>>>> At some time in the future, we aim to build a consolidated logging
> >>>>> database
> >>>>> that will capture logging data from our server application suite. The
> >>>>> information that needs to be logged will differ per
> >>>>> service/applicaption
> >>>>> and
> >>>>> to that end I would aim to have a table schema that has the standard
> >>>>> logging
> >>>>> columns plus a generic XML column (no defined schema) to act as a
> >>>>> property
> >>>>> bag for custom information associated with a specific event.
> >>>>>
> >>>>> We don't have time to develop the logging repository at present,
> >>>>> however
> >>>>> I'm
> >>>>> stressing that we should build logging into our code from the start
> >>>>> rather
> >>>>> than trying to retro-fitting it later which would be far more costly.
> >>>>>
> >>>>> So I need my code to be able to fire off logging messages with a list
> >>>>> or
> >>>>> arbitrary custom properties that get formatted into an XML string.
> For
> >>>>> now
> >>>>> the messages can be written to a text file and later we'll configure
> >>>>> and
> >>>>> AdoNetAppender to write to out logging database.
> >>>>>
> >>>>> So my questions are:
> >>>>> - Is this possible using configuration only? (I susopect not)
> >>>>> - If not then which custom objects do I need to create? From what
> I've
> >>>>> seen
> >>>>> so far I think I'll need to code my own Layout Class
> >>>>> - The ILog interface doesn't doesn't expose a method that takes a
> >>>>> property
> >>>>> bag (or dictionary), but it appears that the LoggingEvent object
> does.
> >>>>> Does
> >>>>> that mean I would have to make my logging calls using
> >>>>> ILog.Logger.Log()?
> >>>>> - Could someone provide some sample code please?
> >>>>> --
> >>>>> View this message in context:
> >>>>>
> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
> >>>>> Sent from the Log4net - Users mailing list archive at Nabble.com.
> >>>>>
> >>>>>
> >>>>
> >>>>
> >>>
> >>>
> >>
> >>
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25011405.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.
>
>

Re: Adding custom logging properties

Posted by AdamTappis <ad...@hotmail.com>.
OK,

So far I've created the following 2 very simple classes which appear to give
me what I need:

    class EventPropertiesXMLLayout : XmlLayoutBase
    {
        protected override void FormatXml(XmlWriter writer, LoggingEvent
loggingEvent)
        {
            LogMessage lm = loggingEvent.MessageObject as LogMessage;
            if (lm != null)
            {
                writer.WriteStartElement("LogEntry");
                writer.WriteStartElement("Message");
                writer.WriteValue(lm.Message);
                writer.WriteEndElement();
                writer.WriteStartElement("Properties");
                foreach (DictionaryEntry de in lm.Properties)
                {                    
                    writer.WriteStartElement(de.Key.ToString());
                    writer.WriteValue(de.Value.ToString());
                    writer.WriteEndElement();
                }
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
        }
    }

    class LogMessage
    {
        private string _message;
        private Hashtable _properties;

        public LogMessage(string message)
        {
            _message = message;
            _properties = new Hashtable();
        }

        public string Message
        {
            get 
            {
                return _message;
            }
        }

        public Hashtable Properties
        {
            get 
            {
                return _properties;
            }
        }
    }

And then write the following code if I have to collect custom properties:

            LogMessage lm = new LogMessage("This is a custom log message");
            lm.Properties.Add("prop1", "value1");
            lm.Properties.Add("prop2", "value2");
            log.Info(lm);


Can you see any immediate issues or limitations with this approach?


AdamTappis wrote:
> 
> How about if I create a custom LogMessage Class that has the message and
> distionary as properties and then write a cutom ObjectRenderer for my
> custom class. This would give my developers the flexibility of either
> logging strings or the custom LogMessage if they require additional
> properties. I guess what it doesn't give me is the flexibility or
> rendering the object to a file using one format and to a DB using a
> different formats. Objects of the specified type would always be rendered
> the same way.
> 
> 
> AdamTappis wrote:
>> 
>> Having a closer look at the documentation, the Properties property of the
>> LoggingEvent class is a PropertiesDictionary which derives from
>> ReadOnlyPropertiesDictionary which menas it can't be written to and hence
>> it's not suitable for my purposes.
>> 
>> Any ideas?
>> 
>> 
>> AdamTappis wrote:
>>> 
>>> Ross,
>>> 
>>> I guess that's why I'm posting here, because I'm trying to devise a
>>> pattern and some coding guidelines so that all our applications log
>>> consistently. I considered wrapping log4net but all I've read advises
>>> against that. So what I'm trying to achieve is an elegant solution that
>>> makes the best use of the framework.
>>> 
>>> You're right, I wish to log a collection of Key-Value pairs associated
>>> with a given loggin event. e.g.
>>> statistics -
>>> <eventData><duration>3ms</duration><size>10kb</size></eventData>
>>> details -
>>> <eventData><customerID>3</customerID><orderID>10</orderID></eventData>
>>> 
>>> The question I'm asking is how best to implement this with log4net?
>>> 
>>> Should I write a wrapper or a helper class that accepts the key-Value
>>> pairs collection as a parameter and returns a formattred XML string that
>>> then get's logged?
>>> 
>>> Maybe I should be creating a LoggingEvent in code manually, adding the
>>> Key-Value pairs to the Properties collection and then using
>>> ILog.Logger.Log to actually log the event rather than using Ilog.Info()
>>> to log. I could than write a custom layout class that serialises the
>>> properties out as an XML string.
>>> 
>>> like I said, I'm not sure and am looking for some disrection.
>>> 
>>> Ideally I would have the following interface available to me:
>>> 
>>> ILog.Info(string message, Dictionary customProperties)
>>> 
>>> and then it would be the configuration that drives how the
>>> customProperties are rendered by specifying the approporiate Layout
>>> class. That way I could format the customProperties to a file in one way
>>> and to a Db as XML etc... without embedding the formatting logic in my
>>> code.
>>> 
>>> 
>>> Ross Hinkley wrote:
>>>> 
>>>> Adam,
>>>> 
>>>> How are these properties getting transformed from a logging call to
>>>> XML?
>>>> Are you asking if there's a way to modify a custom format on the fly
>>>> and
>>>> then turn the custom properties into XML?  (I'm thinking of something
>>>> like
>>>> appending name-value pairs to the log format and having a custom
>>>> appender do
>>>> the XML conversion for you.  This doesn't seem terribly elegant.)
>>>> 
>>>> Maybe I'm over-trivializing, but it seems to me you should be able to
>>>> use
>>>> custom properties to take care of your current needs, converting your
>>>> properties to XML in code, then modifying the ADO appender
>>>> configuration to
>>>> handle that property appropriately when the logging database is
>>>> implemented.
>>>> 
>>>> I guess another question would be what sorts of things need to be
>>>> serialized?  Are they going to be serialized from a class?
>>>> 
>>>> -Ross
>>>> 
>>>> On Mon, Aug 17, 2009 at 8:12 AM, AdamTappis <ad...@hotmail.com>
>>>> wrote:
>>>> 
>>>>>
>>>>> Hi,
>>>>>
>>>>> I've been evaluating log4net recently with a view to using the
>>>>> framework as
>>>>> a loggin standard for our enterprise applicaption. I see it very easy
>>>>> to
>>>>> extend the framework, however I have some specific logging
>>>>> requirements and
>>>>> I'm not sure what would be the easiest way implement these with
>>>>> minimal
>>>>> coding.
>>>>>
>>>>> At some time in the future, we aim to build a consolidated logging
>>>>> database
>>>>> that will capture logging data from our server application suite. The
>>>>> information that needs to be logged will differ per
>>>>> service/applicaption
>>>>> and
>>>>> to that end I would aim to have a table schema that has the standard
>>>>> logging
>>>>> columns plus a generic XML column (no defined schema) to act as a
>>>>> property
>>>>> bag for custom information associated with a specific event.
>>>>>
>>>>> We don't have time to develop the logging repository at present,
>>>>> however
>>>>> I'm
>>>>> stressing that we should build logging into our code from the start
>>>>> rather
>>>>> than trying to retro-fitting it later which would be far more costly.
>>>>>
>>>>> So I need my code to be able to fire off logging messages with a list
>>>>> or
>>>>> arbitrary custom properties that get formatted into an XML string. For
>>>>> now
>>>>> the messages can be written to a text file and later we'll configure
>>>>> and
>>>>> AdoNetAppender to write to out logging database.
>>>>>
>>>>> So my questions are:
>>>>> - Is this possible using configuration only? (I susopect not)
>>>>> - If not then which custom objects do I need to create? From what I've
>>>>> seen
>>>>> so far I think I'll need to code my own Layout Class
>>>>> - The ILog interface doesn't doesn't expose a method that takes a
>>>>> property
>>>>> bag (or dictionary), but it appears that the LoggingEvent object does.
>>>>> Does
>>>>> that mean I would have to make my logging calls using
>>>>> ILog.Logger.Log()?
>>>>> - Could someone provide some sample code please?
>>>>> --
>>>>> View this message in context:
>>>>> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
>>>>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>>>>>
>>>>>
>>>> 
>>>> 
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25011405.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Re: Adding custom logging properties

Posted by AdamTappis <ad...@hotmail.com>.
How about if I create a custom LogMessage Class that has the message and
distionary as properties and then write a cutom ObjectRenderer for my custom
class. This would give my developers the flexibility of either logging
strings or the custom LogMessage if they require additional properties. I
guess what it doesn't give me is the flexibility or rendering the object to
a file using one format and to a DB using a different formats. Objects of
the specified type would always be rendered the same way.


AdamTappis wrote:
> 
> Having a closer look at the documentation, the Properties property of the
> LoggingEvent class is a PropertiesDictionary which derives from
> ReadOnlyPropertiesDictionary which menas it can't be written to and hence
> it's not suitable for my purposes.
> 
> Any ideas?
> 
> 
> AdamTappis wrote:
>> 
>> Ross,
>> 
>> I guess that's why I'm posting here, because I'm trying to devise a
>> pattern and some coding guidelines so that all our applications log
>> consistently. I considered wrapping log4net but all I've read advises
>> against that. So what I'm trying to achieve is an elegant solution that
>> makes the best use of the framework.
>> 
>> You're right, I wish to log a collection of Key-Value pairs associated
>> with a given loggin event. e.g.
>> statistics -
>> <eventData><duration>3ms</duration><size>10kb</size></eventData>
>> details -
>> <eventData><customerID>3</customerID><orderID>10</orderID></eventData>
>> 
>> The question I'm asking is how best to implement this with log4net?
>> 
>> Should I write a wrapper or a helper class that accepts the key-Value
>> pairs collection as a parameter and returns a formattred XML string that
>> then get's logged?
>> 
>> Maybe I should be creating a LoggingEvent in code manually, adding the
>> Key-Value pairs to the Properties collection and then using
>> ILog.Logger.Log to actually log the event rather than using Ilog.Info()
>> to log. I could than write a custom layout class that serialises the
>> properties out as an XML string.
>> 
>> like I said, I'm not sure and am looking for some disrection.
>> 
>> Ideally I would have the following interface available to me:
>> 
>> ILog.Info(string message, Dictionary customProperties)
>> 
>> and then it would be the configuration that drives how the
>> customProperties are rendered by specifying the approporiate Layout
>> class. That way I could format the customProperties to a file in one way
>> and to a Db as XML etc... without embedding the formatting logic in my
>> code.
>> 
>> 
>> Ross Hinkley wrote:
>>> 
>>> Adam,
>>> 
>>> How are these properties getting transformed from a logging call to XML?
>>> Are you asking if there's a way to modify a custom format on the fly and
>>> then turn the custom properties into XML?  (I'm thinking of something
>>> like
>>> appending name-value pairs to the log format and having a custom
>>> appender do
>>> the XML conversion for you.  This doesn't seem terribly elegant.)
>>> 
>>> Maybe I'm over-trivializing, but it seems to me you should be able to
>>> use
>>> custom properties to take care of your current needs, converting your
>>> properties to XML in code, then modifying the ADO appender configuration
>>> to
>>> handle that property appropriately when the logging database is
>>> implemented.
>>> 
>>> I guess another question would be what sorts of things need to be
>>> serialized?  Are they going to be serialized from a class?
>>> 
>>> -Ross
>>> 
>>> On Mon, Aug 17, 2009 at 8:12 AM, AdamTappis <ad...@hotmail.com>
>>> wrote:
>>> 
>>>>
>>>> Hi,
>>>>
>>>> I've been evaluating log4net recently with a view to using the
>>>> framework as
>>>> a loggin standard for our enterprise applicaption. I see it very easy
>>>> to
>>>> extend the framework, however I have some specific logging requirements
>>>> and
>>>> I'm not sure what would be the easiest way implement these with minimal
>>>> coding.
>>>>
>>>> At some time in the future, we aim to build a consolidated logging
>>>> database
>>>> that will capture logging data from our server application suite. The
>>>> information that needs to be logged will differ per
>>>> service/applicaption
>>>> and
>>>> to that end I would aim to have a table schema that has the standard
>>>> logging
>>>> columns plus a generic XML column (no defined schema) to act as a
>>>> property
>>>> bag for custom information associated with a specific event.
>>>>
>>>> We don't have time to develop the logging repository at present,
>>>> however
>>>> I'm
>>>> stressing that we should build logging into our code from the start
>>>> rather
>>>> than trying to retro-fitting it later which would be far more costly.
>>>>
>>>> So I need my code to be able to fire off logging messages with a list
>>>> or
>>>> arbitrary custom properties that get formatted into an XML string. For
>>>> now
>>>> the messages can be written to a text file and later we'll configure
>>>> and
>>>> AdoNetAppender to write to out logging database.
>>>>
>>>> So my questions are:
>>>> - Is this possible using configuration only? (I susopect not)
>>>> - If not then which custom objects do I need to create? From what I've
>>>> seen
>>>> so far I think I'll need to code my own Layout Class
>>>> - The ILog interface doesn't doesn't expose a method that takes a
>>>> property
>>>> bag (or dictionary), but it appears that the LoggingEvent object does.
>>>> Does
>>>> that mean I would have to make my logging calls using
>>>> ILog.Logger.Log()?
>>>> - Could someone provide some sample code please?
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
>>>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>> 
>>> 
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25010448.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Re: Adding custom logging properties

Posted by AdamTappis <ad...@hotmail.com>.
Thanks Ron, that looks like it will allow me to populate the Properties
collection of the LoggingEvent instance.

Then, considering that the actual properties logged will differ per event I
guess I would combine this with my custom Layout class.

I think that gives me what I need.

Thanks again.


Ron Grabowski wrote:
> 
> public class LogManager
> {
>  public static GetLogger<T>()
>  {
>   return new LogEx(LogManager.GetLogger(typeof(T)));
>  }
> }
> 
> // untested...I think I'm forgetting a constructor
> public class LogEx : LogImpl
> {
>  private readonly static Type declaringType = typeof(LogEx);
> 
>  public void Info(string message, IDictionary properties)
>  {
>   if (IsInfoEnabled)
>   {
>    LoggingEvent loggingEvent = new LoggingEvent(
>     declaringType,
>     Logger.Repository,
>     Logger.Name,
>     Level.Info,
>     message,
>     t);
>    foreach (var entry in properites)
>    {
>     loggingEvent.Properties[entry.Key.ToString()] = entry.Value;
>    }
>    Logger.Log(loggingEvent);
>   }
>  }
> }
> 
> http://www.mail-archive.com/log4net-user@logging.apache.org/msg04357.html
> 
> 
> ----- Original Message ----
> From: AdamTappis <ad...@hotmail.com>
> To: log4net-user@logging.apache.org
> Sent: Monday, August 17, 2009 11:08:44 AM
> Subject: Re: Adding custom logging properties
> 
> 
> Having a closer look at the documentation, the Properties property of the
> LoggingEvent class is a PropertiesDictionary which derives from
> ReadOnlyPropertiesDictionary which menas it can't be written to and hence
> it's not suitable for my purposes.
> 
> Any ideas?
> 
> 
> AdamTappis wrote:
>> 
>> Ross,
>> 
>> I guess that's why I'm posting here, because I'm trying to devise a
>> pattern and some coding guidelines so that all our applications log
>> consistently. I considered wrapping log4net but all I've read advises
>> against that. So what I'm trying to achieve is an elegant solution that
>> makes the best use of the framework.
>> 
>> You're right, I wish to log a collection of Key-Value pairs associated
>> with a given loggin event. e.g.
>> statistics -
>> <eventData><duration>3ms</duration><size>10kb</size></eventData>
>> details -
>> <eventData><customerID>3</customerID><orderID>10</orderID></eventData>
>> 
>> The question I'm asking is how best to implement this with log4net?
>> 
>> Should I write a wrapper or a helper class that accepts the key-Value
>> pairs collection as a parameter and returns a formattred XML string that
>> then get's logged?
>> 
>> Maybe I should be creating a LoggingEvent in code manually, adding the
>> Key-Value pairs to the Properties collection and then using
>> ILog.Logger.Log to actually log the event rather than using Ilog.Info()
>> to
>> log. I could than write a custom layout class that serialises the
>> properties out as an XML string.
>> 
>> like I said, I'm not sure and am looking for some disrection.
>> 
>> Ideally I would have the following interface available to me:
>> 
>> ILog.Info(string message, Dictionary customProperties)
>> 
>> and then it would be the configuration that drives how the
>> customProperties are rendered by specifying the approporiate Layout
>> class.
>> That way I could format the customProperties to a file in one way and to
>> a
>> Db as XML etc... without embedding the formatting logic in my code.
>> 
>> 
>> Ross Hinkley wrote:
>>> 
>>> Adam,
>>> 
>>> How are these properties getting transformed from a logging call to XML?
>>> Are you asking if there's a way to modify a custom format on the fly and
>>> then turn the custom properties into XML?  (I'm thinking of something
>>> like
>>> appending name-value pairs to the log format and having a custom
>>> appender
>>> do
>>> the XML conversion for you.  This doesn't seem terribly elegant.)
>>> 
>>> Maybe I'm over-trivializing, but it seems to me you should be able to
>>> use
>>> custom properties to take care of your current needs, converting your
>>> properties to XML in code, then modifying the ADO appender configuration
>>> to
>>> handle that property appropriately when the logging database is
>>> implemented.
>>> 
>>> I guess another question would be what sorts of things need to be
>>> serialized?  Are they going to be serialized from a class?
>>> 
>>> -Ross
>>> 
>>> On Mon, Aug 17, 2009 at 8:12 AM, AdamTappis <ad...@hotmail.com>
>>> wrote:
>>> 
>>>>
>>>> Hi,
>>>>
>>>> I've been evaluating log4net recently with a view to using the
>>>> framework
>>>> as
>>>> a loggin standard for our enterprise applicaption. I see it very easy
>>>> to
>>>> extend the framework, however I have some specific logging requirements
>>>> and
>>>> I'm not sure what would be the easiest way implement these with minimal
>>>> coding.
>>>>
>>>> At some time in the future, we aim to build a consolidated logging
>>>> database
>>>> that will capture logging data from our server application suite. The
>>>> information that needs to be logged will differ per
>>>> service/applicaption
>>>> and
>>>> to that end I would aim to have a table schema that has the standard
>>>> logging
>>>> columns plus a generic XML column (no defined schema) to act as a
>>>> property
>>>> bag for custom information associated with a specific event.
>>>>
>>>> We don't have time to develop the logging repository at present,
>>>> however
>>>> I'm
>>>> stressing that we should build logging into our code from the start
>>>> rather
>>>> than trying to retro-fitting it later which would be far more costly.
>>>>
>>>> So I need my code to be able to fire off logging messages with a list
>>>> or
>>>> arbitrary custom properties that get formatted into an XML string. For
>>>> now
>>>> the messages can be written to a text file and later we'll configure
>>>> and
>>>> AdoNetAppender to write to out logging database.
>>>>
>>>> So my questions are:
>>>> - Is this possible using configuration only? (I susopect not)
>>>> - If not then which custom objects do I need to create? From what I've
>>>> seen
>>>> so far I think I'll need to code my own Layout Class
>>>> - The ILog interface doesn't doesn't expose a method that takes a
>>>> property
>>>> bag (or dictionary), but it appears that the LoggingEvent object does.
>>>> Does
>>>> that mean I would have to make my logging calls using
>>>> ILog.Logger.Log()?
>>>> - Could someone provide some sample code please?
>>>> --
>>>> View this message in context:
>>>> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
>>>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>>>>
>>>>
>>> 
>>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25008536.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.
> 
> 

-- 
View this message in context: http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25023045.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Re: Adding custom logging properties

Posted by Ron Grabowski <ro...@yahoo.com>.
public class LogManager
{
 public static GetLogger<T>()
 {
  return new LogEx(LogManager.GetLogger(typeof(T)));
 }
}

// untested...I think I'm forgetting a constructor
public class LogEx : LogImpl
{
 private readonly static Type declaringType = typeof(LogEx);

 public void Info(string message, IDictionary properties)
 {
  if (IsInfoEnabled)
  {
   LoggingEvent loggingEvent = new LoggingEvent(
    declaringType,
    Logger.Repository,
    Logger.Name,
    Level.Info,
    message,
    t);
   foreach (var entry in properites)
   {
    loggingEvent.Properties[entry.Key.ToString()] = entry.Value;
   }
   Logger.Log(loggingEvent);
  }
 }
}

http://www.mail-archive.com/log4net-user@logging.apache.org/msg04357.html


----- Original Message ----
From: AdamTappis <ad...@hotmail.com>
To: log4net-user@logging.apache.org
Sent: Monday, August 17, 2009 11:08:44 AM
Subject: Re: Adding custom logging properties


Having a closer look at the documentation, the Properties property of the
LoggingEvent class is a PropertiesDictionary which derives from
ReadOnlyPropertiesDictionary which menas it can't be written to and hence
it's not suitable for my purposes.

Any ideas?


AdamTappis wrote:
> 
> Ross,
> 
> I guess that's why I'm posting here, because I'm trying to devise a
> pattern and some coding guidelines so that all our applications log
> consistently. I considered wrapping log4net but all I've read advises
> against that. So what I'm trying to achieve is an elegant solution that
> makes the best use of the framework.
> 
> You're right, I wish to log a collection of Key-Value pairs associated
> with a given loggin event. e.g.
> statistics -
> <eventData><duration>3ms</duration><size>10kb</size></eventData>
> details -
> <eventData><customerID>3</customerID><orderID>10</orderID></eventData>
> 
> The question I'm asking is how best to implement this with log4net?
> 
> Should I write a wrapper or a helper class that accepts the key-Value
> pairs collection as a parameter and returns a formattred XML string that
> then get's logged?
> 
> Maybe I should be creating a LoggingEvent in code manually, adding the
> Key-Value pairs to the Properties collection and then using
> ILog.Logger.Log to actually log the event rather than using Ilog.Info() to
> log. I could than write a custom layout class that serialises the
> properties out as an XML string.
> 
> like I said, I'm not sure and am looking for some disrection.
> 
> Ideally I would have the following interface available to me:
> 
> ILog.Info(string message, Dictionary customProperties)
> 
> and then it would be the configuration that drives how the
> customProperties are rendered by specifying the approporiate Layout class.
> That way I could format the customProperties to a file in one way and to a
> Db as XML etc... without embedding the formatting logic in my code.
> 
> 
> Ross Hinkley wrote:
>> 
>> Adam,
>> 
>> How are these properties getting transformed from a logging call to XML?
>> Are you asking if there's a way to modify a custom format on the fly and
>> then turn the custom properties into XML?  (I'm thinking of something
>> like
>> appending name-value pairs to the log format and having a custom appender
>> do
>> the XML conversion for you.  This doesn't seem terribly elegant.)
>> 
>> Maybe I'm over-trivializing, but it seems to me you should be able to use
>> custom properties to take care of your current needs, converting your
>> properties to XML in code, then modifying the ADO appender configuration
>> to
>> handle that property appropriately when the logging database is
>> implemented.
>> 
>> I guess another question would be what sorts of things need to be
>> serialized?  Are they going to be serialized from a class?
>> 
>> -Ross
>> 
>> On Mon, Aug 17, 2009 at 8:12 AM, AdamTappis <ad...@hotmail.com>
>> wrote:
>> 
>>>
>>> Hi,
>>>
>>> I've been evaluating log4net recently with a view to using the framework
>>> as
>>> a loggin standard for our enterprise applicaption. I see it very easy to
>>> extend the framework, however I have some specific logging requirements
>>> and
>>> I'm not sure what would be the easiest way implement these with minimal
>>> coding.
>>>
>>> At some time in the future, we aim to build a consolidated logging
>>> database
>>> that will capture logging data from our server application suite. The
>>> information that needs to be logged will differ per service/applicaption
>>> and
>>> to that end I would aim to have a table schema that has the standard
>>> logging
>>> columns plus a generic XML column (no defined schema) to act as a
>>> property
>>> bag for custom information associated with a specific event.
>>>
>>> We don't have time to develop the logging repository at present, however
>>> I'm
>>> stressing that we should build logging into our code from the start
>>> rather
>>> than trying to retro-fitting it later which would be far more costly.
>>>
>>> So I need my code to be able to fire off logging messages with a list or
>>> arbitrary custom properties that get formatted into an XML string. For
>>> now
>>> the messages can be written to a text file and later we'll configure and
>>> AdoNetAppender to write to out logging database.
>>>
>>> So my questions are:
>>> - Is this possible using configuration only? (I susopect not)
>>> - If not then which custom objects do I need to create? From what I've
>>> seen
>>> so far I think I'll need to code my own Layout Class
>>> - The ILog interface doesn't doesn't expose a method that takes a
>>> property
>>> bag (or dictionary), but it appears that the LoggingEvent object does.
>>> Does
>>> that mean I would have to make my logging calls using ILog.Logger.Log()?
>>> - Could someone provide some sample code please?
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
>>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>>>
>>>
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25008536.html
Sent from the Log4net - Users mailing list archive at Nabble.com.

Re: Adding custom logging properties

Posted by AdamTappis <ad...@hotmail.com>.
Having a closer look at the documentation, the Properties property of the
LoggingEvent class is a PropertiesDictionary which derives from
ReadOnlyPropertiesDictionary which menas it can't be written to and hence
it's not suitable for my purposes.

Any ideas?


AdamTappis wrote:
> 
> Ross,
> 
> I guess that's why I'm posting here, because I'm trying to devise a
> pattern and some coding guidelines so that all our applications log
> consistently. I considered wrapping log4net but all I've read advises
> against that. So what I'm trying to achieve is an elegant solution that
> makes the best use of the framework.
> 
> You're right, I wish to log a collection of Key-Value pairs associated
> with a given loggin event. e.g.
> statistics -
> <eventData><duration>3ms</duration><size>10kb</size></eventData>
> details -
> <eventData><customerID>3</customerID><orderID>10</orderID></eventData>
> 
> The question I'm asking is how best to implement this with log4net?
> 
> Should I write a wrapper or a helper class that accepts the key-Value
> pairs collection as a parameter and returns a formattred XML string that
> then get's logged?
> 
> Maybe I should be creating a LoggingEvent in code manually, adding the
> Key-Value pairs to the Properties collection and then using
> ILog.Logger.Log to actually log the event rather than using Ilog.Info() to
> log. I could than write a custom layout class that serialises the
> properties out as an XML string.
> 
> like I said, I'm not sure and am looking for some disrection.
> 
> Ideally I would have the following interface available to me:
> 
> ILog.Info(string message, Dictionary customProperties)
> 
> and then it would be the configuration that drives how the
> customProperties are rendered by specifying the approporiate Layout class.
> That way I could format the customProperties to a file in one way and to a
> Db as XML etc... without embedding the formatting logic in my code.
> 
> 
> Ross Hinkley wrote:
>> 
>> Adam,
>> 
>> How are these properties getting transformed from a logging call to XML?
>> Are you asking if there's a way to modify a custom format on the fly and
>> then turn the custom properties into XML?  (I'm thinking of something
>> like
>> appending name-value pairs to the log format and having a custom appender
>> do
>> the XML conversion for you.  This doesn't seem terribly elegant.)
>> 
>> Maybe I'm over-trivializing, but it seems to me you should be able to use
>> custom properties to take care of your current needs, converting your
>> properties to XML in code, then modifying the ADO appender configuration
>> to
>> handle that property appropriately when the logging database is
>> implemented.
>> 
>> I guess another question would be what sorts of things need to be
>> serialized?  Are they going to be serialized from a class?
>> 
>> -Ross
>> 
>> On Mon, Aug 17, 2009 at 8:12 AM, AdamTappis <ad...@hotmail.com>
>> wrote:
>> 
>>>
>>> Hi,
>>>
>>> I've been evaluating log4net recently with a view to using the framework
>>> as
>>> a loggin standard for our enterprise applicaption. I see it very easy to
>>> extend the framework, however I have some specific logging requirements
>>> and
>>> I'm not sure what would be the easiest way implement these with minimal
>>> coding.
>>>
>>> At some time in the future, we aim to build a consolidated logging
>>> database
>>> that will capture logging data from our server application suite. The
>>> information that needs to be logged will differ per service/applicaption
>>> and
>>> to that end I would aim to have a table schema that has the standard
>>> logging
>>> columns plus a generic XML column (no defined schema) to act as a
>>> property
>>> bag for custom information associated with a specific event.
>>>
>>> We don't have time to develop the logging repository at present, however
>>> I'm
>>> stressing that we should build logging into our code from the start
>>> rather
>>> than trying to retro-fitting it later which would be far more costly.
>>>
>>> So I need my code to be able to fire off logging messages with a list or
>>> arbitrary custom properties that get formatted into an XML string. For
>>> now
>>> the messages can be written to a text file and later we'll configure and
>>> AdoNetAppender to write to out logging database.
>>>
>>> So my questions are:
>>> - Is this possible using configuration only? (I susopect not)
>>> - If not then which custom objects do I need to create? From what I've
>>> seen
>>> so far I think I'll need to code my own Layout Class
>>> - The ILog interface doesn't doesn't expose a method that takes a
>>> property
>>> bag (or dictionary), but it appears that the LoggingEvent object does.
>>> Does
>>> that mean I would have to make my logging calls using ILog.Logger.Log()?
>>> - Could someone provide some sample code please?
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
>>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>>>
>>>
>> 
>> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25008536.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Re: Adding custom logging properties

Posted by AdamTappis <ad...@hotmail.com>.
Ross,

I guess that's why I'm posting here, because I'm trying to devise a pattern
and some coding guidelines so that all our applications log consistently. I
considered wrapping log4net but all I've read advises against that. So what
I'm trying to achieve is an elegant solution that makes the best use of the
framework.

You're right, I wish to log a collection of Key-Value pairs associated with
a given loggin event. e.g.
statistics -
<eventData><duration>3ms</duration><size>10kb</size></eventData>
details -
<eventData><customerID>3</customerID><orderID>10</orderID></eventData>

The question I'm asking is how best to implement this with log4net?

Should I write a wrapper or a helper class that accepts the key-Value pairs
collection as a parameter and returns a formattred XML string that then
get's logged?

Maybe I should be creating a LoggingEvent in code manually, adding the
Key-Value pairs to the Properties collection and then using ILog.Logger.Log
to actually log the event rather than using Ilog.Info() to log. I could than
write a custom layout class that serialises the properties out as an XML
string.

like I said, I'm not sure and am looking for some disrection.

Ideally I would have the following interface available to me:

ILog.Info(string message, Dictionary customProperties)

and then it would be the configuration that drives how the customProperties
are rendered by specifying the approporiate Layout class. That way I could
format the customProperties to a file in one way and to a Db as XML etc...
without embedding the formatting logic in my code.


Ross Hinkley wrote:
> 
> Adam,
> 
> How are these properties getting transformed from a logging call to XML?
> Are you asking if there's a way to modify a custom format on the fly and
> then turn the custom properties into XML?  (I'm thinking of something like
> appending name-value pairs to the log format and having a custom appender
> do
> the XML conversion for you.  This doesn't seem terribly elegant.)
> 
> Maybe I'm over-trivializing, but it seems to me you should be able to use
> custom properties to take care of your current needs, converting your
> properties to XML in code, then modifying the ADO appender configuration
> to
> handle that property appropriately when the logging database is
> implemented.
> 
> I guess another question would be what sorts of things need to be
> serialized?  Are they going to be serialized from a class?
> 
> -Ross
> 
> On Mon, Aug 17, 2009 at 8:12 AM, AdamTappis <ad...@hotmail.com>
> wrote:
> 
>>
>> Hi,
>>
>> I've been evaluating log4net recently with a view to using the framework
>> as
>> a loggin standard for our enterprise applicaption. I see it very easy to
>> extend the framework, however I have some specific logging requirements
>> and
>> I'm not sure what would be the easiest way implement these with minimal
>> coding.
>>
>> At some time in the future, we aim to build a consolidated logging
>> database
>> that will capture logging data from our server application suite. The
>> information that needs to be logged will differ per service/applicaption
>> and
>> to that end I would aim to have a table schema that has the standard
>> logging
>> columns plus a generic XML column (no defined schema) to act as a
>> property
>> bag for custom information associated with a specific event.
>>
>> We don't have time to develop the logging repository at present, however
>> I'm
>> stressing that we should build logging into our code from the start
>> rather
>> than trying to retro-fitting it later which would be far more costly.
>>
>> So I need my code to be able to fire off logging messages with a list or
>> arbitrary custom properties that get formatted into an XML string. For
>> now
>> the messages can be written to a text file and later we'll configure and
>> AdoNetAppender to write to out logging database.
>>
>> So my questions are:
>> - Is this possible using configuration only? (I susopect not)
>> - If not then which custom objects do I need to create? From what I've
>> seen
>> so far I think I'll need to code my own Layout Class
>> - The ILog interface doesn't doesn't expose a method that takes a
>> property
>> bag (or dictionary), but it appears that the LoggingEvent object does.
>> Does
>> that mean I would have to make my logging calls using ILog.Logger.Log()?
>> - Could someone provide some sample code please?
>> --
>> View this message in context:
>> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>>
>>
> 
> 

-- 
View this message in context: http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25008083.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


Re: Adding custom logging properties

Posted by Ross Hinkley <ro...@gmail.com>.
Adam,

How are these properties getting transformed from a logging call to XML?
Are you asking if there's a way to modify a custom format on the fly and
then turn the custom properties into XML?  (I'm thinking of something like
appending name-value pairs to the log format and having a custom appender do
the XML conversion for you.  This doesn't seem terribly elegant.)

Maybe I'm over-trivializing, but it seems to me you should be able to use
custom properties to take care of your current needs, converting your
properties to XML in code, then modifying the ADO appender configuration to
handle that property appropriately when the logging database is implemented.

I guess another question would be what sorts of things need to be
serialized?  Are they going to be serialized from a class?

-Ross

On Mon, Aug 17, 2009 at 8:12 AM, AdamTappis <ad...@hotmail.com> wrote:

>
> Hi,
>
> I've been evaluating log4net recently with a view to using the framework as
> a loggin standard for our enterprise applicaption. I see it very easy to
> extend the framework, however I have some specific logging requirements and
> I'm not sure what would be the easiest way implement these with minimal
> coding.
>
> At some time in the future, we aim to build a consolidated logging database
> that will capture logging data from our server application suite. The
> information that needs to be logged will differ per service/applicaption
> and
> to that end I would aim to have a table schema that has the standard
> logging
> columns plus a generic XML column (no defined schema) to act as a property
> bag for custom information associated with a specific event.
>
> We don't have time to develop the logging repository at present, however
> I'm
> stressing that we should build logging into our code from the start rather
> than trying to retro-fitting it later which would be far more costly.
>
> So I need my code to be able to fire off logging messages with a list or
> arbitrary custom properties that get formatted into an XML string. For now
> the messages can be written to a text file and later we'll configure and
> AdoNetAppender to write to out logging database.
>
> So my questions are:
> - Is this possible using configuration only? (I susopect not)
> - If not then which custom objects do I need to create? From what I've seen
> so far I think I'll need to code my own Layout Class
> - The ILog interface doesn't doesn't expose a method that takes a property
> bag (or dictionary), but it appears that the LoggingEvent object does. Does
> that mean I would have to make my logging calls using ILog.Logger.Log()?
> - Could someone provide some sample code please?
> --
> View this message in context:
> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.
>
>

RE: Adding custom logging properties

Posted by Karim Bourouba <ka...@hotmail.com>.

Ah, i think I see.
 
Have you considered just logging the XML as a string to the DB, then use something else to parse it at a latter stage?



 

> Date: Mon, 17 Aug 2009 06:48:42 -0700
> From: adamtappis@hotmail.com
> To: log4net-user@logging.apache.org
> Subject: RE: Adding custom logging properties
> 
> 
> Hi Karim,
> 
> No that's not my question.
> 
> Apart from a custom message I also wish to log some custom event data i.e. a
> collection of properties. The target for this will eventually be a SQL table
> which has an XML type column i.e. rathert han just adding a customerID I
> might have 10 different properties to add.
> 
> Using the global context for this is not an acceptable solution -
> assuggested in one of the other threads I read. 
> 
> 
> Karim Bourouba wrote:
> > 
> > 
> > I have to say I only glanced through this very quickly and I am a little
> > confused. I am at work just now, so my attention is split, please bear
> > with me.
> > 
> > 
> > 
> > Are you asking if custom messages can be logged via log4net? If so, then
> > the quick answer is yes. Implementation is very simple as well, but in
> > case I missed your point can you let us know if this is what you are
> > after?
> > 
> > 
> > 
> > Seems like this is the log4net topic of the day today :)
> > 
> > 
> > 
> > 
> > 
> >> Date: Mon, 17 Aug 2009 06:12:29 -0700
> >> From: adamtappis@hotmail.com
> >> To: log4net-user@logging.apache.org
> >> Subject: Adding custom logging properties
> >> 
> >> 
> >> Hi,
> >> 
> >> I've been evaluating log4net recently with a view to using the framework
> >> as
> >> a loggin standard for our enterprise applicaption. I see it very easy to
> >> extend the framework, however I have some specific logging requirements
> >> and
> >> I'm not sure what would be the easiest way implement these with minimal
> >> coding.
> >> 
> >> At some time in the future, we aim to build a consolidated logging
> >> database
> >> that will capture logging data from our server application suite. The
> >> information that needs to be logged will differ per service/applicaption
> >> and
> >> to that end I would aim to have a table schema that has the standard
> >> logging
> >> columns plus a generic XML column (no defined schema) to act as a
> >> property
> >> bag for custom information associated with a specific event.
> >> 
> >> We don't have time to develop the logging repository at present, however
> >> I'm
> >> stressing that we should build logging into our code from the start
> >> rather
> >> than trying to retro-fitting it later which would be far more costly.
> >> 
> >> So I need my code to be able to fire off logging messages with a list or
> >> arbitrary custom properties that get formatted into an XML string. For
> >> now
> >> the messages can be written to a text file and later we'll configure and
> >> AdoNetAppender to write to out logging database.
> >> 
> >> So my questions are:
> >> - Is this possible using configuration only? (I susopect not)
> >> - If not then which custom objects do I need to create? From what I've
> >> seen
> >> so far I think I'll need to code my own Layout Class
> >> - The ILog interface doesn't doesn't expose a method that takes a
> >> property
> >> bag (or dictionary), but it appears that the LoggingEvent object does.
> >> Does
> >> that mean I would have to make my logging calls using ILog.Logger.Log()?
> >> - Could someone provide some sample code please?
> >> -- 
> >> View this message in context:
> >> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
> >> Sent from the Log4net - Users mailing list archive at Nabble.com.
> >> 
> > 
> > _________________________________________________________________
> > Windows Live Messenger: Celebrate 10 amazing years with free winks and
> > emoticons.
> > http://clk.atdmt.com/UKM/go/157562755/direct/01/
> > 
> ;-);-)
> -- 
> View this message in context: http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25007016.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.
> 

_________________________________________________________________

Upgrade to Internet Explorer 8 Optimised for MSN.  

http://extras.uk.msn.com/internet-explorer-8/?ocid=T010MSN07A0716U

RE: Adding custom logging properties

Posted by AdamTappis <ad...@hotmail.com>.
Hi Karim,

No that's not my question.

Apart from a custom message I also wish to log some custom event data i.e. a
collection of properties. The target for this will eventually be a SQL table
which has an XML type column i.e. rathert han just adding a customerID I
might have 10 different properties to add.

Using the global context for this is not an acceptable solution -
assuggested in one of the other threads I read. 


Karim Bourouba wrote:
> 
> 
> I have to say I only glanced through this very quickly and I am a little
> confused. I am at work just now, so my attention is split, please bear
> with me.
> 
>  
> 
> Are you asking if custom messages can be logged via log4net? If so, then
> the quick answer is yes. Implementation is very simple as well, but in
> case I missed your point can you let us know if this is what you are
> after?
> 
>  
> 
> Seems like this is the log4net topic of the day today :)
> 
> 
>  
> 
> 
>> Date: Mon, 17 Aug 2009 06:12:29 -0700
>> From: adamtappis@hotmail.com
>> To: log4net-user@logging.apache.org
>> Subject: Adding custom logging properties
>> 
>> 
>> Hi,
>> 
>> I've been evaluating log4net recently with a view to using the framework
>> as
>> a loggin standard for our enterprise applicaption. I see it very easy to
>> extend the framework, however I have some specific logging requirements
>> and
>> I'm not sure what would be the easiest way implement these with minimal
>> coding.
>> 
>> At some time in the future, we aim to build a consolidated logging
>> database
>> that will capture logging data from our server application suite. The
>> information that needs to be logged will differ per service/applicaption
>> and
>> to that end I would aim to have a table schema that has the standard
>> logging
>> columns plus a generic XML column (no defined schema) to act as a
>> property
>> bag for custom information associated with a specific event.
>> 
>> We don't have time to develop the logging repository at present, however
>> I'm
>> stressing that we should build logging into our code from the start
>> rather
>> than trying to retro-fitting it later which would be far more costly.
>> 
>> So I need my code to be able to fire off logging messages with a list or
>> arbitrary custom properties that get formatted into an XML string. For
>> now
>> the messages can be written to a text file and later we'll configure and
>> AdoNetAppender to write to out logging database.
>> 
>> So my questions are:
>> - Is this possible using configuration only? (I susopect not)
>> - If not then which custom objects do I need to create? From what I've
>> seen
>> so far I think I'll need to code my own Layout Class
>> - The ILog interface doesn't doesn't expose a method that takes a
>> property
>> bag (or dictionary), but it appears that the LoggingEvent object does.
>> Does
>> that mean I would have to make my logging calls using ILog.Logger.Log()?
>> - Could someone provide some sample code please?
>> -- 
>> View this message in context:
>> http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
>> Sent from the Log4net - Users mailing list archive at Nabble.com.
>> 
> 
> _________________________________________________________________
> Windows Live Messenger: Celebrate 10 amazing years with free winks and
> emoticons.
> http://clk.atdmt.com/UKM/go/157562755/direct/01/
> 
;-);-)
-- 
View this message in context: http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25007016.html
Sent from the Log4net - Users mailing list archive at Nabble.com.


RE: Adding custom logging properties

Posted by Karim Bourouba <ka...@hotmail.com>.
I have to say I only glanced through this very quickly and I am a little confused. I am at work just now, so my attention is split, please bear with me.

 

Are you asking if custom messages can be logged via log4net? If so, then the quick answer is yes. Implementation is very simple as well, but in case I missed your point can you let us know if this is what you are after?

 

Seems like this is the log4net topic of the day today :)


 


> Date: Mon, 17 Aug 2009 06:12:29 -0700
> From: adamtappis@hotmail.com
> To: log4net-user@logging.apache.org
> Subject: Adding custom logging properties
> 
> 
> Hi,
> 
> I've been evaluating log4net recently with a view to using the framework as
> a loggin standard for our enterprise applicaption. I see it very easy to
> extend the framework, however I have some specific logging requirements and
> I'm not sure what would be the easiest way implement these with minimal
> coding.
> 
> At some time in the future, we aim to build a consolidated logging database
> that will capture logging data from our server application suite. The
> information that needs to be logged will differ per service/applicaption and
> to that end I would aim to have a table schema that has the standard logging
> columns plus a generic XML column (no defined schema) to act as a property
> bag for custom information associated with a specific event.
> 
> We don't have time to develop the logging repository at present, however I'm
> stressing that we should build logging into our code from the start rather
> than trying to retro-fitting it later which would be far more costly.
> 
> So I need my code to be able to fire off logging messages with a list or
> arbitrary custom properties that get formatted into an XML string. For now
> the messages can be written to a text file and later we'll configure and
> AdoNetAppender to write to out logging database.
> 
> So my questions are:
> - Is this possible using configuration only? (I susopect not)
> - If not then which custom objects do I need to create? From what I've seen
> so far I think I'll need to code my own Layout Class
> - The ILog interface doesn't doesn't expose a method that takes a property
> bag (or dictionary), but it appears that the LoggingEvent object does. Does
> that mean I would have to make my logging calls using ILog.Logger.Log()?
> - Could someone provide some sample code please?
> -- 
> View this message in context: http://www.nabble.com/Adding-custom-logging-properties-tp25006538p25006538.html
> Sent from the Log4net - Users mailing list archive at Nabble.com.
> 

_________________________________________________________________
Windows Live Messenger: Celebrate 10 amazing years with free winks and emoticons.
http://clk.atdmt.com/UKM/go/157562755/direct/01/