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 730375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T06:54:16+00:00 2026-05-14T06:54:16+00:00

I have app.config in m win application, and loggingConfiguration section (enterprise library 4.1). I

  • 0

I have app.config in m win application, and loggingConfiguration section (enterprise library 4.1).

I need do this programatically,

Get a list of all listener in loggingConfiguration

Modify property fileName=”.\Trazas\Excepciones.log” of several RollingFlatFileTraceListener’s

Modify several properties of AuthenticatingEmailTraceListener listener,

Any suggestions, I havent found any reference or samples

<listeners>

  <add name="Excepciones RollingFile Listener" fileName=".\Trazas\Excepciones.log" 
       formatter="Text Single Formatter" 
       footer="&lt;/Excepcion&gt;" 
       header="&lt;Excepcion&gt;"
       rollFileExistsBehavior="Overwrite" rollInterval="None" rollSizeKB="1500" timeStampPattern="yyyy-MM-dd" 
       listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" traceOutputOptions="None" filter="All" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />


  <add name="AuthEmailTraceListener"
            type="zzzz.Frk.Logging.AuthEmailTraceListener.AuthenticatingEmailTraceListener, zzzz.Frk.Logging.AuthEmailTraceListener"
            listenerDataType="zzzz.Frk.Logging.AuthEmailTraceListener.AuthenticatingEmailTraceListenerData, zzzz.Frk.Logging.AuthEmailTraceListener"
            formatter="Exception Formatter"
            traceOutputOptions="None"
            toAddress="xxxx@gmail.com"
            fromAddress="xxxx@gmail.com"
            subjectLineStarter=" Excepción detectada - "
            subjectLineEnder="incidencias"
            smtpServer="smtp.gmail.com"
            smtpPort="587" 
            authenticate="true"
            username="xxxxxxx@gmail.com"
            password="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
            enableSsl="true"
       />
  • 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-14T06:54:16+00:00Added an answer on May 14, 2026 at 6:54 am

    I’m not sure if you can do it programmatically. You would have to map the configuration data to the actual implementation classes (and properties). Plus, if the config is currently being used, you would have to ensure that the programmatic changes would override the config.

    In this example, I read the config in, change some settings, copy the config and write it back to the config file. This is made laborious because many properties are readonly so new objects need to be created. The writing of the config should work but I haven’t tested actually calling Enterprise Library after doing this (and I really wouldn’t recommend doing it for a production application).

    // Open config file
    ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
    fileMap.ExeConfigFilename = @"MyApp.exe.config";
    
    Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
    
    // Get EL log settings
    LoggingSettings log = config.GetSection("loggingConfiguration") as LoggingSettings;
    List<TraceListenerData> newListeners = new List<TraceListenerData>();
    
    foreach(TraceListenerData listener in log.TraceListeners)
    {
        // set new values for TraceListeners
        if (listener is FormattedEventLogTraceListenerData)
        {
            FormattedEventLogTraceListenerData oldData = listener as FormattedEventLogTraceListenerData;
            FormattedEventLogTraceListenerData data = 
                new FormattedEventLogTraceListenerData(oldData.Name, oldData.Source + "new", oldData.Log, oldData.MachineName, oldData.Formatter, oldData.TraceOutputOptions);
    
            newListeners.Add(data);
        }
        else if (listener is RollingFlatFileTraceListenerData)
        {
            RollingFlatFileTraceListenerData oldData = listener as RollingFlatFileTraceListenerData;
            RollingFlatFileTraceListenerData data =
                new RollingFlatFileTraceListenerData(oldData.Name, oldData.FileName + ".new", oldData.Header, oldData.Footer, oldData.RollSizeKB, oldData.TimeStampPattern, oldData.RollFileExistsBehavior, oldData.RollInterval, oldData.TraceOutputOptions, oldData.Formatter, oldData.Filter);
    
            newListeners.Add(data);
        }
    }
    
    // Replace the listeners
    foreach (TraceListenerData traceListener in newListeners)
    {
        log.TraceListeners.Remove(traceListener.Name);
        log.TraceListeners.Add(traceListener);
    }
    
    // Copy the LogSettings since when config.Sections.Remove() is called the original log object becomes "empty". 
    LoggingSettings newLog = new LoggingSettings();
    
    newLog.DefaultCategory = log.DefaultCategory;
    
    foreach (var formatter in log.Formatters)
    {
        newLog.Formatters.Add(formatter);
    }
    
    foreach (var filter in log.LogFilters)
    {
        newLog.LogFilters.Add(filter);
    }
    
    foreach (var listener in log.TraceListeners)
    {
        newLog.TraceListeners.Add(listener);
    }
    
    foreach (var source in log.TraceSources)
    {
        newLog.TraceSources.Add(source);
    }
    
    newLog.LogWarningWhenNoCategoriesMatch = log.LogWarningWhenNoCategoriesMatch;
    newLog.RevertImpersonation = log.RevertImpersonation;
    newLog.SpecialTraceSources = log.SpecialTraceSources;
    newLog.TracingEnabled = log.TracingEnabled;
    
    // replace section
    config.Sections.Remove("loggingConfiguration");
    config.Sections.Add("loggingConfiguration", newLog);
    
    // save and reload config
    config.Save(ConfigurationSaveMode.Modified, true);
    ConfigurationManager.RefreshSection("loggingConfiguration");
    

    If this isn’t 100% what you wanted hopefully it gives you some ideas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a custom section in my app.config file related to our IoC container
I have a class library that contains a valid connectionString inside the app.config. Inside
I have an app.config file inside my TestProject, but when I try to read
When I have one app.config in my main project I always have to duplicate
If I have the following setting in my app.config file. It is a setting
I have a .net interop project that uses an app.config file. When I am
I have a .net project (MySolution.Common) that uses the app.config. I am using the
Does anyone have an XSLT that will take the app.config and render it into
I am just learning about app.config in respect of creating custom sections. I have
We have an app with an extensive admin section. We got a little trigger

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.