none
Changer dynamiquement l'adresse du File path dans Enterprise Library 5.0 / c# RRS feed

  • Discussion générale

  • Comment changer l'adresse du file path des logs durant le Run Time sachant que l'adresse par défaut est mise au début par le baie de la configuration à partir du framework  Enterprise Library 5 ?

    fichier de la config enterprise Library:

    <loggingConfiguration name="" tracingEnabled="true" defaultCategory="General">
            <listeners>
                <add name="Event Log Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FormattedEventLogTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FormattedEventLogTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    source="Enterprise Library Logging" formatter="Text Formatter"
                    log="" machineName="." traceOutputOptions="None" />
                <add name="Rolling Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollingFlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.RollingFlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    fileName="C:\Documents and Settings\kbaiche\Desktop\logggg.log"
                    formatter="Text Formatter" traceOutputOptions="None" />
                <add name="Flat File Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.FlatFileTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.FlatFileTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
                    fileName="C:\Documents and Settings\kbaiche\Desktop\trace.log"
                    formatter="Text Formatter" />
            </listeners>

    j'ai essayé avec ce code mais ça ne marche pas !!:

    tring logFilePath = @"C:\Documents and Settings\kbaiche\test\" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
     
                ConfigurationFileMap objConfigPath = new ConfigurationFileMap();
     
                // App config file path. 
                string appPath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
                objConfigPath.MachineConfigFilename = appPath;
     
                Configuration entLibConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
     
                LoggingSettings loggingSettings = (LoggingSettings)entLibConfig.GetSection(LoggingSettings.SectionName);
     
                TraceListenerData traceListenerData = loggingSettings.TraceListeners.Get("Flat File Trace Listener");
                FlatFileTraceListenerData objFlatFileTraceListenerData = traceListenerData as FlatFileTraceListenerData;
     
                objFlatFileTraceListenerData.FileName = logFilePath;
     
                entLibConfig.Save();
    
    
    

    • Type modifié Aurel Bera vendredi 7 juin 2013 10:56 Discussion
    vendredi 31 mai 2013 13:39