How to push the List<> values in Ilogger.Info

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to push the List<> values in Ilogger.Info

Goyal, Nitin   UTAS

Hi

 

I have a huge list of data say like 5k values and I want to push them into the logger.Info of log4net.

If there are individual string values, I am able to do so and accordingly modified the conversion pattern but now I want to push all those values in the list and thus is there anyway I can do so.

Also, I need to modify the conversion pattern too. For conversion pattern, I can make a string using for loop and override the Patternlayout class and set the conversion pattern for all the 5k values but how to put those values from List to those values?

 

Nitin Goyal – Technical Lead, Software – Sensors & Integrated Systems

UTC AEROSPACE SYSTEMS

Netra Tech Park, Old Plot No.181, New Plot No. 40, EPIP Industrial Area, Part of Sy.No.28, Kundalahalli Village, Krishnaraja Puram Hobli, Bangalore 560 066, Karnataka, India

Tel: +91 80 673 80262  Mobile: +91 9886295724  Fax: +91 80 673 80005

[hidden email]    www.utcaerospacesystems.com

 

CONFIDENTIALITY WARNING:  This message may contain proprietary and/or privileged information of UTC Aerospace Systems and its affiliated companies.  If you are not the intended recipient, please 1) do not disclose, copy, distribute or use this message or its contents, 2) advise the sender by return e-mail, and 3) delete all copies (including all attachments) from your computer.  Your cooperation is greatly appreciated.

 

Reply | Threaded
Open this post in threaded view
|

Re: How to push the List<> values in Ilogger.Info

rmashal
Hello Nitin,

There are two ways to do that. The first is using filters on the main log appender. The filter would redirect messages to a different converter and it will all be done within the configuration. This option requires that the special data text will have an identifying property such as a log level or a unique string in the text. Read about log4net filters to find out more.

If you do not have a special property or text you can use to filter the messages, you can use the second approach, where you create a separate logger and appender for the data:

<appender type="...FileAppender" name="SpecialDataAppender">
     <file value="specialdatafile"/>
     <layout>
         <conversionPattern value=" special pattern for data "/>
     .....
</appender>

<logger name="specialDataLogger">
   <additivity value="false"/>
   <appender-ref ref="SpecialDataAppender"/>
</logger>

Then, use this logger in a method that would dump the data to the log file:

DumpData:
    log = log4net.....GetLogger("specialDataLogger");
    foreach (var item in specialData)
       log.Info(item);

This will give you a separate log file for the special data.

However, I assume that you want it incorporated into the main log file, right?

If so, you will have to change both appenders: that of the main file and that of the special data file, to use "minimal lock". Here's an example:

  <appender name="MainLogFile" type="log4net.Appender.FileAppender">
    <file value="myapplog.log" />
    <appendToFile value="false" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="..."/>
    </layout>
  </appender>
<appender name="SpecialDataAppender" type="log4net.Appender.FileAppender">
    <file value="myapplog.log" />
    <appendToFile value="true" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value=" special data pattern "/>
    </layout>
  </appender>

This will incorporate the special data text into the main log file.


Hope this answers your question.

Ronen Mashal.



On Thu, Oct 30, 2014 at 9:01 AM, Goyal, Nitin UTAS <[hidden email]> wrote:

Hi

 

I have a huge list of data say like 5k values and I want to push them into the logger.Info of log4net.

If there are individual string values, I am able to do so and accordingly modified the conversion pattern but now I want to push all those values in the list and thus is there anyway I can do so.

Also, I need to modify the conversion pattern too. For conversion pattern, I can make a string using for loop and override the Patternlayout class and set the conversion pattern for all the 5k values but how to put those values from List to those values?

 

Nitin Goyal – Technical Lead, Software – Sensors & Integrated Systems

UTC AEROSPACE SYSTEMS

Netra Tech Park, Old Plot No.181, New Plot No. 40, EPIP Industrial Area, Part of Sy.No.28, Kundalahalli Village, Krishnaraja Puram Hobli, Bangalore 560 066, Karnataka, India

Tel: +91 80 673 80262  Mobile: <a href="tel:%2B91%209886295724" value="+919886295724" target="_blank">+91 9886295724  Fax: +91 80 673 80005

[hidden email]    www.utcaerospacesystems.com

 

CONFIDENTIALITY WARNING:  This message may contain proprietary and/or privileged information of UTC Aerospace Systems and its affiliated companies.  If you are not the intended recipient, please 1) do not disclose, copy, distribute or use this message or its contents, 2) advise the sender by return e-mail, and 3) delete all copies (including all attachments) from your computer.  Your cooperation is greatly appreciated.

 




--

 

email_sig
Ronen Mashal

Software Engineer | Magic Software Enterprises Ltd.

Tel. +972-3-5389215       |       Fax. +972-3-5389333
[hidden email] | www.magicsoftware.com | FacebookTwitterLinkedinYouTubeGoogle+Magic Software Blog

 



DISCLAIMER. Information in this message and its attachments may be privileged or confidential. It is for the exclusive use of the intended recipient(s). 
If you are not one of the intended recipients, you are hereby informed that any use, disclosure, distribution, and/or copying of this information is strictly prohibited. 
If you receive this message in error, please notify the sender immediately and delete all copies of this message. We recommend that you scan your incoming Emails. 
We cannot accept responsibility for any transmitted viruses.