internal void ReplaceStructureHolder(LogWriterStructureHolder newStructureHolder) { try { structureHolderLock.AcquireWriterLock(writerLockAcquireTimeout); try { // Switch old and new structures. LogWriterStructureHolder oldStructureHolder = structureHolder; structureHolder = newStructureHolder; filter = new LogFilterHelper(structureHolder.Filters, this); // Dispose has to be fully performed before allowing the new structure to be used. oldStructureHolder.Dispose(); } finally { structureHolderLock.ReleaseWriterLock(); } } catch (ApplicationException) { TryLogLockAcquisitionFailure(Resources.ExceptionFailedToAcquireLockToUpdate); } }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Builds a <see cref="LogWriter"/> described by the <see cref="LoggingSettings"/> configuration section. /// </summary> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="name">The name of the instance to build. It is part of the <see cref="ICustomFactory.CreateObject(IBuilderContext, string, IConfigurationSource, ConfigurationReflectionCache)"/> method, but it is not used in this implementation.</param> /// <param name="configurationSource">The source for configuration objects.</param> /// <param name="reflectionCache">The cache to use retrieving reflection information.</param> /// <returns>A fully initialized instance of <see cref="LogWriter"/>.</returns> public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { LogWriterStructureHolder structureHolder = (LogWriterStructureHolder)LogWriterStructureHolderCustomFactory.Instance.CreateObject(context, name, configurationSource, reflectionCache); LogWriterStructureHolderUpdater structureHolderUpdater = new LogWriterStructureHolderUpdater(configurationSource); LogWriter createdObject = new LogWriter(structureHolder, structureHolderUpdater); structureHolderUpdater.SetLogWriter(createdObject); // add the writer to the locator, if necessary. if (context.Locator != null) { ILifetimeContainer lifetime = context.Locator.Get <ILifetimeContainer>(typeof(ILifetimeContainer), SearchMode.Local); if (lifetime != null) { context.Locator.Add(new DependencyResolutionLocatorKey(typeof(LogWriter), name), createdObject); lifetime.Add(createdObject); } } return(createdObject); }
internal LogWriter(LogWriterStructureHolder structureHolder, ILogWriterStructureUpdater structureUpdater) { this.structureHolder = structureHolder; this.filter = new LogFilterHelper(structureHolder.Filters, this); this.structureUpdater = structureUpdater; instrumentationProvider = new LoggingInstrumentationProvider(); }
/// <summary> /// Initializes a new instance of the <see cref="LogWriterImpl"/> class. /// </summary> /// <param name="structureHolder">The initial implementation of the logging stack</param> /// <param name="instrumentationProvider">The instrumentation provider to use.</param> /// <param name="updateCoordinator">The coordinator for logging operations.</param> public LogWriterImpl( LogWriterStructureHolder structureHolder, ILoggingInstrumentationProvider instrumentationProvider, ILoggingUpdateCoordinator updateCoordinator) { Guard.ArgumentNotNull(structureHolder, "structureHolder"); Guard.ArgumentNotNull(instrumentationProvider, "instrumentationProvider"); Guard.ArgumentNotNull(updateCoordinator, "updateCoordinator"); this.instrumentationProvider = instrumentationProvider; this.ReplaceStructureHolder(structureHolder); this.updateCoordinator = updateCoordinator; this.updateCoordinator.RegisterLoggingUpdateHandler(this); }
public void UpdateLogWriter(object sender, ConfigurationChangedEventArgs args) { if (logWriter != null) { try { LogWriterStructureHolder newStructureHolder = EnterpriseLibraryFactory.BuildUp <LogWriterStructureHolder>(configurationSource); logWriter.ReplaceStructureHolder(newStructureHolder); } catch (ConfigurationErrorsException configurationException) { logWriter.ReportConfigurationFailure(configurationException); } } }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Builds a <see cref="LogWriterStructureHolder"/> described by the <see cref="LoggingSettings"/> configuration section. /// </summary> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="name">The name of the instance to build. It is part of the <see cref="ICustomFactory.CreateObject(IBuilderContext, string, IConfigurationSource, ConfigurationReflectionCache)"/> method, but it is not used in this implementation.</param> /// <param name="configurationSource">The source for configuration objects.</param> /// <param name="reflectionCache">The cache to use retrieving reflection information.</param> /// <returns>A fully initialized instance of <see cref="LogWriterStructureHolder"/>.</returns> public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { LoggingSettings loggingSettings = LoggingSettings.GetLoggingSettings(configurationSource); ValidateLoggingSettings(loggingSettings); TraceListenerCustomFactory.TraceListenerCache traceListenerCache = TraceListenerCustomFactory.CreateTraceListenerCache(loggingSettings.TraceListeners.Count); ICollection <ILogFilter> logFilters = new List <ILogFilter>(); foreach (LogFilterData logFilterData in loggingSettings.LogFilters) { logFilters.Add(LogFilterCustomFactory.Instance.Create(context, logFilterData, configurationSource, reflectionCache)); } IDictionary <string, LogSource> traceSources = new Dictionary <string, LogSource>(); foreach (TraceSourceData traceSourceData in loggingSettings.TraceSources) { traceSources.Add(traceSourceData.Name, LogSourceCustomFactory.Instance.Create(context, traceSourceData, configurationSource, reflectionCache, traceListenerCache)); } LogSource allEventsTraceSource = LogSourceCustomFactory.Instance.Create(context, loggingSettings.SpecialTraceSources.AllEventsTraceSource, configurationSource, reflectionCache, traceListenerCache); LogSource notProcessedTraceSource = LogSourceCustomFactory.Instance.Create(context, loggingSettings.SpecialTraceSources.NotProcessedTraceSource, configurationSource, reflectionCache, traceListenerCache); LogSource errorsTraceSource = LogSourceCustomFactory.Instance.Create(context, loggingSettings.SpecialTraceSources.ErrorsTraceSource, configurationSource, reflectionCache, traceListenerCache); LogWriterStructureHolder createdObject = new LogWriterStructureHolder( logFilters, traceSources, allEventsTraceSource, notProcessedTraceSource, errorsTraceSource, loggingSettings.DefaultCategory, loggingSettings.TracingEnabled, loggingSettings.LogWarningWhenNoCategoriesMatch); return(createdObject); }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Builds a <see cref="LogWriterStructureHolder"/> described by the <see cref="LoggingSettings"/> configuration section. /// </summary> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="name">The name of the instance to build. It is part of the <see cref="ICustomFactory.CreateObject(IBuilderContext, string, IConfigurationSource, ConfigurationReflectionCache)"/> method, but it is not used in this implementation.</param> /// <param name="configurationSource">The source for configuration objects.</param> /// <param name="reflectionCache">The cache to use retrieving reflection information.</param> /// <returns>A fully initialized instance of <see cref="LogWriterStructureHolder"/>.</returns> public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { LoggingSettings loggingSettings = LoggingSettings.GetLoggingSettings(configurationSource); ValidateLoggingSettings(loggingSettings); TraceListenerCustomFactory.TraceListenerCache traceListenerCache = TraceListenerCustomFactory.CreateTraceListenerCache(loggingSettings.TraceListeners.Count); ICollection<ILogFilter> logFilters = new List<ILogFilter>(); foreach (LogFilterData logFilterData in loggingSettings.LogFilters) { logFilters.Add(LogFilterCustomFactory.Instance.Create(context, logFilterData, configurationSource, reflectionCache)); } IDictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>(); foreach (TraceSourceData traceSourceData in loggingSettings.TraceSources) { traceSources.Add(traceSourceData.Name, LogSourceCustomFactory.Instance.Create(context, traceSourceData, configurationSource, reflectionCache, traceListenerCache)); } LogSource allEventsTraceSource = LogSourceCustomFactory.Instance.Create(context, loggingSettings.SpecialTraceSources.AllEventsTraceSource, configurationSource, reflectionCache, traceListenerCache); LogSource notProcessedTraceSource = LogSourceCustomFactory.Instance.Create(context, loggingSettings.SpecialTraceSources.NotProcessedTraceSource, configurationSource, reflectionCache, traceListenerCache); LogSource errorsTraceSource = LogSourceCustomFactory.Instance.Create(context, loggingSettings.SpecialTraceSources.ErrorsTraceSource, configurationSource, reflectionCache, traceListenerCache); LogWriterStructureHolder createdObject = new LogWriterStructureHolder( logFilters, traceSources, allEventsTraceSource, notProcessedTraceSource, errorsTraceSource, loggingSettings.DefaultCategory, loggingSettings.TracingEnabled, loggingSettings.LogWarningWhenNoCategoriesMatch); return createdObject; }
public object CreateObject(IBuilderContext context, string name, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { LogWriterStructureHolder structureHolder = (LogWriterStructureHolder) LogWriterStructureHolderCustomFactory.Instance.CreateObject(context, name, configurationSource, reflectionCache); LogWriterStructureHolderUpdater structureHolderUpdater = new LogWriterStructureHolderUpdater(configurationSource); LogWriter createdObject = new LogWriter(structureHolder, structureHolderUpdater); structureHolderUpdater.SetLogWriter(createdObject); if (context.Locator != null) { context.Locator.Add(new NamedTypeBuildKey(typeof(LogWriter), name), createdObject); } if (context.Lifetime != null) { context.Lifetime.Add(createdObject); } return(createdObject); }
/// <summary> /// Creates an Enterprise Library exception handler that utilizes /// a rolling flat file trace listener to write to log files. /// </summary> /// <param name="Name">The name of the <see cref="EnterpriseExceptionLogging.LoggingExceptionHandler"/>.</param> /// <param name="FilePath">Location of log file. If this is not provided, <see cref="DEFAULT_CONFIG_FILE_PATH"/> is used to try and retrieve file path from Web.config file.</param> /// <param name="FileName">Name of log file. If this is not provided, "default_rolling.log" is used.</param> /// <param name="Interval">How often a new file should be created.</param> /// <param name="Save">States whether or not to store the handler in memory.</param> /// <returns></returns> private EnterpriseExceptionLogging.LoggingExceptionHandler CreateTempLogger(string Name = "", string FilePath = "", string FileName = "", LoggingInterval Interval = LoggingInterval.Day, /*bool ForceCreate = false,*/ bool Save = true) { string default_file_path = FilePath; if (string.IsNullOrEmpty(default_file_path)) { try { default_file_path = ConfigurationManager.AppSettings[DEFAULT_CONFIG_FILE_PATH]; } catch (ConfigurationErrorsException) { } } if (string.IsNullOrEmpty(default_file_path)) { return(default(EnterpriseExceptionLogging.LoggingExceptionHandler)); } if (string.IsNullOrEmpty(Name)) { Name = default_file_path + (!string.IsNullOrEmpty(FileName) ? FileName : "default_rolling.log"); } string FullName = default_file_path + (!string.IsNullOrEmpty(FileName) ? FileName : "default_rolling.log"); if (!FullName.EndsWith(".log")) { FullName += ".log"; } if (_temp_enterprise_loggers.ContainsKey(Name)) { return(_temp_enterprise_loggers[Name]); } EnterpriseExceptionLogging.LoggingExceptionHandler handler = default(EnterpriseExceptionLogging.LoggingExceptionHandler); try { //EnterpriseLogging.LogWriter writer = default(EnterpriseLogging.LogWriter); //using (EnterpriseLogging.LogWriterFactory factory = new EnterpriseLogging.LogWriterFactory()) //using (writer = factory.CreateDefault()) //{ // if (writer == null) // return handler; // if (!ForceCreate && writer.TraceSources.Count > 0) // { // // there already exists listeners in web config that we do // // not want to overwrite, so there is no need to create a // // default listener // return handler; // } //} // create formatter for rolling log file EnterpriseLogging.Formatters.TextFormatter formatter = new EnterpriseLogging.Formatters.TextFormatter( template: "GMT Timestamp: {timestamp(MM/dd/yyyy HH:mm:ss)}\n" + "Local Timestamp: {timestamp(local:hh:mm:ss:tt)}\n" + "Message: {message}\n" + "Category: {category}\n" + "Priority: {priority}\n" + "EventId: {eventid}\n" + "Severity: {severity}\n" + "Title:{title}\n" + "Machine: {machine}\n" + "Application Domain: {appDomain}\n" + "Process Id: {processId}\n" + "Process Name: {processName}\n" + "Win32 Thread Id: {win32ThreadId}\n" + "Thread Name: {threadName}\n" + "Extended Properties: {dictionary({key} - {value})}\n"); EnterpriseLogging.TraceListeners.RollInterval interval; if (!Enum.TryParse(Enum.GetName(typeof(LoggingInterval), Interval), true, out interval)) { interval = EnterpriseLogging.TraceListeners.RollInterval.Day; } // create trace listener for exception handler EnterpriseLogging.TraceListeners.RollingFlatFileTraceListener listener = new EnterpriseLogging.TraceListeners.RollingFlatFileTraceListener( fileName: FullName, header: "----------------------------------------", footer: "----------------------------------------", formatter: formatter, rollSizeKB: 0, timeStampPattern: "yyyy-MM-dd", rollFileExistsBehavior: EnterpriseLogging.TraceListeners.RollFileExistsBehavior.Overwrite, rollInterval: interval); listener.TraceOutputOptions = TraceOptions.None; listener.Name = "Default Rolling Flat File Trace Listener"; // add trace listener to the log writer's sources //if (OverwriteTraceListeners) // writer.TraceSources.Clear(); //if (writer.TraceSources.ContainsKey("General")) // writer.TraceSources["General"].Listeners.Add(listener); //else // writer.TraceSources.Add( // key: "General", // value: new EnterpriseLogging.LogSource( // name: "Default Enterprise Logger", // level: SourceLevels.All, // traceListeners: new List<TraceListener>(1) { listener }, // autoFlush: true // )); // create the exception handler that will handle the exceptions //handler = new EnterpriseExceptionLogging.LoggingExceptionHandler( // logCategory: "General", // eventId: 100, // severity: TraceEventType.Error, // title: "Default Enterprise Library Exception Handler", // priority: 0, // formatterType: typeof(TextExceptionFormatter), // writer: writer); //List<EnterpriseLogging.Filters.LogFilter> filters = new List<EnterpriseLogging.Filters.LogFilter>(); //EnterpriseLogging.LogSource main_source = new EnterpriseLogging.LogSource( // name: "Default Enterprise Logger", // level: SourceLevels.All, // traceListeners: new List<TraceListener>(1) { listener }, // autoFlush: true // ); //IDictionary<string, EnterpriseLogging.LogSource> trace_sources = new Dictionary<string, EnterpriseLogging.LogSource>(); //trace_sources.Add("General", main_source); //EnterpriseLogging.LogWriterStructureHolder holder = new EnterpriseLogging.LogWriterStructureHolder(filters, trace_sources, main_source, main_source, main_source, "General", true, true, false); //EnterpriseLogging.LogWriterImpl writer = new EnterpriseLogging.LogWriterImpl(holder, new EnterpriseLogging.Instrumentation.LoggingInstrumentationProvider(false, true, "EnhancedPartnerCenter"), new EnterpriseLogging.LoggingUpdateCoordinator(new Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ContainerModel.ConfigurationChangeEventSourceImpl())); //handler = new EnterpriseExceptionLogging.LoggingExceptionHandler( // logCategory: "General", // eventId: 100, // severity: TraceEventType.Error, // title: "Default Enterprise Library Exception Handler", // priority: 0, // formatterType: typeof(TextExceptionFormatter), // writer: writer); //if (Save) // _temp_enterprise_loggers.Add(Name, handler); // Try to fix this to work.. List <EnterpriseLogging.Filters.LogFilter> filters = new List <EnterpriseLogging.Filters.LogFilter>(); EnterpriseLogging.LogSource main_source = new EnterpriseLogging.LogSource( name: "Default Enterprise Logger", level: SourceLevels.All, traceListeners: new List <TraceListener>(1) { listener }, autoFlush: true ); IDictionary <string, EnterpriseLogging.LogSource> trace_sources = new Dictionary <string, EnterpriseLogging.LogSource>(); trace_sources.Add("General", main_source); EnterpriseLogging.LogWriterFactory factory_writer = new EnterpriseLogging.LogWriterFactory(); EnterpriseLogging.LogWriterStructureHolder holder = new EnterpriseLogging.LogWriterStructureHolder(filters, trace_sources, main_source, main_source, main_source, "General", true, true, false); EnterpriseLogging.LogWriter writer = factory_writer.Create(); // this is where chiz hit the fan writer.Configure(new Action <EnterpriseLogging.LoggingConfiguration>((EnterpriseLogging.LoggingConfiguration lc) => { lc.AddLogSource(""); })); handler = new EnterpriseExceptionLogging.LoggingExceptionHandler( logCategory: "General", eventId: 100, severity: TraceEventType.Error, title: "Default Enterprise Library Exception Handler", priority: 0, formatterType: typeof(TextExceptionFormatter), writer: writer); } catch (Exception) { handler = default(EnterpriseExceptionLogging.LoggingExceptionHandler); } return(handler); }
internal void ReplaceStructureHolder(LogWriterStructureHolder newStructureHolder) { structureHolder = newStructureHolder; filter = new LogFilterHelper(structureHolder.Filters, this); }