Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 935489
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:09:50+00:00 2026-05-15T21:09:50+00:00

I need logging to: Rolling file, to avoid 1 big log file. CSV format

  • 0

I need logging to:

  1. Rolling file, to avoid 1 big log file.
  2. CSV format for easier look up.

I can see the EntLib (5.0) has the Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener to log to a rolling log file.

To make the log entries look like a CSV row, I can change the Formatters.TextFormatter.Template to put double quote around the values, and also change the Listener’s Footer and Header to nothing, so they won’t be output.

Under normal circumstance, this would give me a well formed CSV file. However if a token value in the Template contain a double quote, this would not be escaped. Hence the log file become an invalid CSV file.

Is there any way to resolve this?

Is there any alternative solutions to this problem?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T21:09:51+00:00Added an answer on May 15, 2026 at 9:09 pm

    See http://msdn.microsoft.com/en-us/library/ff650608.aspx.
    Turn out adding a custom formatter is not that hard, I added a CSVTextFormattter to only take care of massaging the message and extended properties, which works for me.
    Notice I use the bult-in TextFormatter to do all the heavy lifting.

    Sample Config:

    <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
    ...
        <formatters>
          <add type="<your namespace>.CSVTextFormatter, <your dll>"
              template="{timestamp(local)},{severity},{category},{message},{property(ActivityId)},{eventid},{win32ThreadId},{threadName},{dictionary({key} - {value}{newline})}"
              name="CSV Text Formatter" />
        </formatters>...
    </loggingConfiguration>
    

    The class is something like this:

    Public Class CSVTextFormatter
        Implements ILogFormatter
    
        Private Const csTemplateAttributeName As String = "template"
    
        Private moTextFormatter As TextFormatter
        Private Property TextFormatter() As TextFormatter
            Get
                Return moTextFormatter
            End Get
            Set(ByVal value As TextFormatter)
                moTextFormatter = value
            End Set
        End Property
    
        Private moConfigData As System.Collections.Specialized.NameValueCollection
        Private Property ConfigData() As System.Collections.Specialized.NameValueCollection
            Get
                Return moConfigData
            End Get
            Set(ByVal value As System.Collections.Specialized.NameValueCollection)
                moConfigData = value
                If moConfigData.AllKeys.Contains(csTemplateAttributeName) Then
                    TextFormatter = New TextFormatter(moConfigData(csTemplateAttributeName))
                Else
                    TextFormatter = New TextFormatter()
                End If
            End Set
        End Property
    
        Public Sub New()
            TextFormatter = New TextFormatter()
        End Sub
    
        Public Sub New(ByVal configData As System.Collections.Specialized.NameValueCollection)
            Me.ConfigData = configData
        End Sub
    
        Public Function Format(ByVal log As Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry) As String Implements Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter.Format
            Dim oLog As Microsoft.Practices.EnterpriseLibrary.Logging.LogEntry = log.Clone()
            With oLog
                .Message = NormalizeToCSVValue(.Message)
                For Each sKey In .ExtendedProperties.Keys
                    Dim sValue As String = TryCast(.ExtendedProperties(sKey), String)
                    If Not String.IsNullOrEmpty(sValue) Then
                        .ExtendedProperties(sKey) = NormalizeToCSVValue(sValue)
                    End If
                Next
            End With
            Return TextFormatter.Format(oLog)
        End Function
    
        Private Shared Function NormalizeToCSVValue(ByVal text As String) As String
            Dim bWrapLogText = False
            Dim oQualifiers = New String() {""""}
            For Each sQualifier In oQualifiers
                If text.Contains(sQualifier) Then
                    text = text.Replace(sQualifier, String.Format("""{0}""", sQualifier))
                    bWrapLogText = True
                End If
            Next
            Dim oDelimiters = New String() {",", vbLf, vbCr, vbCrLf}
            If text.Contains(oDelimiters) Then
                bWrapLogText = True
            End If
            If bWrapLogText Then
                text = String.Format("""{0}""", text)
            End If
            Return text
        End Function
    
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 496k
  • Answers 496k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This question came from me not really understanding Sunspot-solr, but… May 16, 2026 at 11:39 am
  • Editorial Team
    Editorial Team added an answer Can you make it clear that why you should call… May 16, 2026 at 11:39 am
  • Editorial Team
    Editorial Team added an answer Do you want to support IE <5.5? If not, try… May 16, 2026 at 11:39 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I need a logging framework in my application. I have two candidates: Log4Net and
I'm using logback (with slf4j) to do the logging, and I've got many XML
I'm using a 'rolling' cURL multi implementation (like this SO post , based on
Edit: From another question I provided an answer that has links to a lot
(Note: I have seen several questions regarding .NET logging frameworks, but haven't seen any
I need to find the type of object pointed by pointer. Code is as
Over time I found the need to override several stdlib methods from Python in
Let's say that I'm currently designing an application where I will need to use
Need help understanding what I am doing with the syntax here, please help! I
Need help in figuring out a way to fetch a particular block of content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.