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

  • Home
  • SEARCH
  • 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 9067935
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:04:06+00:00 2026-06-16T17:04:06+00:00

I have a custom LogEntry class – ErrorEntry which derives from LogEntry. It has

  • 0

I have a custom LogEntry class – ErrorEntry which derives from LogEntry. It has a few public properties (a class object is also one of the properties) where I wish to put in additional data.

public class ErrorEntry : LogEntry
{
 public string UserId {get; set; }
 public SessionDetail SessionInfo {get; set; }
}

I also have a custom formatter – MyFormatter

[ConfigurationElementType(typeof(CustomFormatterData))]
public class MyFormatter : ILogFormatter
{
  public MyFormatter(NameValueCollection nvc)
  {
     //not used
  }

  public string Format(LogEntry log)
  {
    string strEntry;
    if(log is ErrorEntry)
    {
       //use properties of ErrorEntry
       //populate returnString
    }
    else
    {
       throw new ArgumentException("Not supported");
    }
    return strEntry;
  }
}

I have set up the web.config settings with the custom formatter and it works fine till the statement where it checks if the variable is of type ErrorEntry – over here it never becomes true and goes into the else block.

I am a bit confused here – is there something else that I need to do? Is this implementation supported by a custom formatter class?

I am using Enterprise Library 3.1.

  • 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-06-16T17:04:07+00:00Added an answer on June 16, 2026 at 5:04 pm

    It works for me if I extend LogFormatter (instead of implementing ILogFormatter) and overriding Format():

    [ConfigurationElementType(typeof(CustomFormatterData))]
    public class MyFormatter : LogFormatter
    {
        public MyFormatter(NameValueCollection nvc)
        {
            //not used
        }
    
        public override string Format(LogEntry log)
        {
            ErrorEntry errorEntry = log as ErrorEntry;
    
            if (errorEntry != null)
            {
                return "This is the string with the custom values: " + errorEntry.UserId;
                //use properties of ErrorEntry
                //populate returnString
            }
    
            return "Not supported";
        }
    }
    

    Along with this configuration:

    <?xml version="1.0"?>
    <configuration>
      <configSections>
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
        <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </configSections>
      <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
        defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
        <listeners>
          <add fileName="trace.log" header="----------------------------------------"
            footer="----------------------------------------" formatter="Custom Formatter"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            traceOutputOptions="None" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=3.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
            name="FlatFile TraceListener" />
        </listeners>
        <formatters>
          <add type="CustomFormatters.MyFormatter, CustomFormatters, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"
            name="Custom Formatter" />
        </formatters>
        <categorySources>
          <add switchValue="All" name="General">
            <listeners>
              <add name="FlatFile TraceListener" />
            </listeners>
          </add>
        </categorySources>
        <specialSources>
          <allEvents switchValue="All" name="All Events" />
          <notProcessed switchValue="All" name="Unprocessed Category" />
          <errors switchValue="All" name="Logging Errors &amp; Warnings">
            <listeners>
              <add name="FlatFile TraceListener" />
            </listeners>
          </errors>
        </specialSources>
      </loggingConfiguration>
      <startup>
        <supportedRuntime version="v2.0.50727" />
      </startup>
    </configuration>
    

    If you don’t pass an ErrorEntry in to Logger.Write() then a LogEntry will be constructed and not a custom ErrorEntry. So, you should always pass an ErrorEntry in and not use the other overloads. E.g.:

    ErrorEntry errorEntry = new ErrorEntry();
    errorEntry.UserId = "ME!";
    errorEntry.Message = "Default message";
    errorEntry.Categories.Add("General");
    
    Logger.Write(errorEntry);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have custom control: public class TestTextBox : TextBox { public TestTextBox() { Text
I have custom radio buttons which I've borrowed from this website: http://www.inserthtml.com/2012/06/custom-form-radio-checkbox/ Unfortunately, I'm
I have custom content type, which has target association. I want to set up
I have custom html helper which getting IEnumerable model from view and generates html
I have custom ImageView: public class ShadowedImageView extends ImageView { private Paint mPaint; public
I have custom type name Netsgroup which is a collection of Net class. Net
I have custom ContentControl called TabItem public class TabItem : ContentControl I have set
I have Custom List to display image with it's name like below... public class
I have custom Rythm template tag (sayHi.html) which I want to call from parent
I have custom app class public class MyApp extends Application { public static Context

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.