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="</Excepcion>"
header="<Excepcion>"
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"
/>
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).
If this isn’t 100% what you wanted hopefully it gives you some ideas.