public void CanDeserializeSerializedDefaultConfiguration() { TraceListenerData data = new TraceListenerData(); Assert.AreEqual(data.TraceOutputOptions, TraceOptions.None); Assert.AreEqual(data.Filter, SourceLevels.All); }
public void SetLogFilePath(string filePath) { ConfigurationFileMap objConfigPath = new ConfigurationFileMap(); // App config file path. string appPath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile; objConfigPath.MachineConfigFilename = appPath; Configuration entLibConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~"); LoggingSettings loggingSettings = (LoggingSettings)entLibConfig.GetSection(LoggingSettings.SectionName); TraceListenerData traceListenerData = loggingSettings.TraceListeners.Get("Flat File Trace Listener"); FlatFileTraceListenerData objFlatFileTraceListenerData = traceListenerData as FlatFileTraceListenerData; objFlatFileTraceListenerData.FileName = filePath; IUnityContainer container = new UnityContainer(); container.AddNewExtension <EnterpriseLibraryCoreExtension>(); // Configurator will read Enterprise Library configuration // and set up the container UnityContainerConfigurator configurator = new UnityContainerConfigurator(container); var loggingXmlConfigSource = new SerializableConfigurationSource(); loggingXmlConfigSource.Add(LoggingSettings.SectionName, loggingSettings); // Configure the container with our own custom logging EnterpriseLibraryContainer.ConfigureContainer(configurator, loggingXmlConfigSource); // Wrap in ServiceLocator IServiceLocator locator = new UnityServiceLocator(container); // And set Enterprise Library to use it EnterpriseLibraryContainer.Current = locator; }
public void Given() { listenerData = new WmiTraceListenerData("listener") { TraceOutputOptions = TraceOptions.Callstack | TraceOptions.ProcessId }; }
public void Setup() { listenerData = new WmiTraceListenerData("listener") { Filter = SourceLevels.Warning }; }
static public void InitializeLogging(string fileName) { LoggingSettings loggingSettings = (LoggingSettings)config.GetSection("loggingConfiguration"); Debug.Assert(loggingSettings != null); TraceListenerData traceListenerData = loggingSettings.TraceListeners.Get("Flat File Trace Listener"); Debug.Assert(traceListenerData != null); FlatFileTraceListenerData file = traceListenerData as FlatFileTraceListenerData; Debug.Assert(file != null); if (fileName == "") { File.Copy(file.FileName, LoggingDirectory + Path.GetFileName(file.FileName)); file.FileName = LoggingDirectory + Path.GetFileName(file.FileName); } else { file.FileName = LoggingDirectory + "\\" + fileName + ".log"; loggingDirectory = Path.GetDirectoryName(file.FileName); } config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("loggingConfiguration"); }
public void Given() { listenerData = new SystemDiagnosticsTraceListenerData( "systemDiagnosticsTraceListener", typeof(System.Diagnostics.TextWriterTraceListener), string.Empty ); }
public void Given() { listenerData = new SystemDiagnosticsTraceListenerData( "systemDiagnosticsTraceListener", typeof(MockSystemDiagsTraceListener), ""); }
public void Setup() { listenerData = new XmlTraceListenerData("listener", "file name") { TraceOutputOptions = TraceOptions.DateTime | TraceOptions.Callstack, Filter = SourceLevels.Warning }; }
public void Setup() { listenerData = new FlatFileTraceListenerData("listener", "filename", "header", "footer", null) { TraceOutputOptions = TraceOptions.DateTime | TraceOptions.Callstack, Filter = SourceLevels.Warning }; }
///<summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Builds a <see cref="CommonLoggingEntlibTraceListener"/> described by a /// <see cref="CommonLoggingEntlibTraceListenerData"/> configuration object. ///</summary> public override TraceListener Assemble(IBuilderContext context, TraceListenerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { CommonLoggingEntlibTraceListenerData data = (CommonLoggingEntlibTraceListenerData)objectConfiguration; ILogFormatter formatter = base.GetFormatter(context, data.Formatter, configurationSource, reflectionCache); CommonLoggingEntlibTraceListener listener = (CommonLoggingEntlibTraceListener)System.Activator.CreateInstance(objectConfiguration.Type, new object[] { objectConfiguration, formatter }); return(listener); }
public void Setup() { listenerData = new FormattedEventLogTraceListenerData("listener", "source", "log", "machine", "formatter") { TraceOutputOptions = TraceOptions.DateTime | TraceOptions.Callstack, Filter = SourceLevels.Warning }; }
public void Setup() { listenerData = new FlatFileTraceListenerData("listener", "filename", "header", "footer", "formatter") { TraceOutputOptions = TraceOptions.DateTime | TraceOptions.Callstack, Filter = SourceLevels.Warning }; }
public void TraceListenerNodeDataTest() { TraceOptions options = TraceOptions.DateTime; TraceListenerData traceListenerData = new TraceListenerData(); traceListenerData.TraceOutputOptions = options; TraceListenerNode traceListenerNode = new TraceListenerNodeImpl(traceListenerData); Assert.AreEqual(options, traceListenerNode.TraceOutputOptions); }
public override TraceListener Assemble(IBuilderContext context, TraceListenerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { WeblogEmailTraceListenerData castedObjectConfiguration = (WeblogEmailTraceListenerData)objectConfiguration; ILogFormatter formatter = GetFormatter(context, castedObjectConfiguration.Formatter, configurationSource, reflectionCache); TraceListener createdObject = new WeblogEmailTraceListener(castedObjectConfiguration.ToAddress, castedObjectConfiguration.FromAddress, castedObjectConfiguration.SubjectLineStarter, castedObjectConfiguration.SubjectLineEnder, castedObjectConfiguration.SmtpServer, castedObjectConfiguration.SmtpPort, castedObjectConfiguration.EnableSsl, castedObjectConfiguration.UserName, castedObjectConfiguration.Password, formatter); return(createdObject); }
public void TraceListenerNodeTest() { TraceOptions options = TraceOptions.DateTime; TraceListenerNode listenerNode = new TraceListenerNodeImpl(new TraceListenerData()); listenerNode.TraceOutputOptions = options; TraceListenerData nodeData = listenerNode.TraceListenerData; Assert.AreEqual(options, nodeData.TraceOutputOptions); }
public void HasDefaultValues() { TraceListenerData data = new TraceListenerData(); Assert.AreEqual(TraceOptions.None, data.TraceOutputOptions); Assert.AreEqual(SourceLevels.All, data.Filter); Assert.AreEqual(false, data.Asynchronous); Assert.AreEqual(30000, data.AsynchronousBufferSize); Assert.AreEqual(Timeout.InfiniteTimeSpan, data.AsynchronousDisposeTimeout); Assert.AreEqual(null, data.AsynchronousMaxDegreeOfParallelism); }
private void CreateTraceListenerNode(TraceListenerData traceListenerData) { TraceListenerNode traceListenerNode = NodeCreationService.CreateNodeByDataType(traceListenerData.GetType(), new object[] { traceListenerData }) as TraceListenerNode; if (null == traceListenerNode) { LogNodeMapError(node, traceListenerData.GetType()); return; } traceListenerNode.SetFormatter(formatters); node.AddNode(traceListenerNode); }
public void TraceListenerNodeEqualsTraceListenerData() { TraceOptions traceOptions = TraceOptions.Callstack; SourceLevels filter = SourceLevels.Critical; TraceListenerNode listener = new TraceListenerNodeImpl(traceOptions, filter); TraceListenerData data = new TraceListenerData(); data.Filter = filter; data.TraceOutputOptions = traceOptions; Assert.AreEqual(listener.TraceOutputOptions, data.TraceOutputOptions); Assert.AreEqual(listener.Filter, data.Filter); }
public void Setup() { listenerData = new EmailTraceListenerData("listener", "to", "from", "subject starter", "subject ender", "smtp", 25, "formatter") { TraceOutputOptions = TraceOptions.DateTime | TraceOptions.Callstack, Filter = SourceLevels.Warning, AuthenticationMode = EmailAuthenticationMode.UserNameAndPassword, UserName = "******", Password = "******", UseSSL = true }; }
public void Setup() { listenerData = new EmailTraceListenerData("listener", "to", "from", "subject starter", "subject ender", "smtp", 25, "") { TraceOutputOptions = TraceOptions.DateTime | TraceOptions.Callstack, Filter = SourceLevels.Warning, AuthenticationMode = EmailAuthenticationMode.UserNameAndPassword, UserName = "******", Password = "******", UseSSL = true }; }
void BuildTraceListeners() { TraceListenerCollectionNode traceListenerCollectionNode = (TraceListenerCollectionNode)hierarchy.FindNodeByType(loggingSettingsNode, typeof(TraceListenerCollectionNode)); if (traceListenerCollectionNode != null) { foreach (TraceListenerNode listenerNode in traceListenerCollectionNode.Nodes) { TraceListenerData data = listenerNode.TraceListenerData; data.Filter = listenerNode.Filter; data.TraceOutputOptions = listenerNode.TraceOutputOptions; loggingSettings.TraceListeners.Add(data); } } }
/// <summary> /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code. /// Builds a <see cref="FormattedDatabaseTraceListener"/> based on an instance of <see cref="FormattedDatabaseTraceListenerData"/>. /// </summary> /// <seealso cref="TraceListenerCustomFactory"/> /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param> /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="FormattedDatabaseTraceListenerData"/>.</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="FormattedDatabaseTraceListener"/>.</returns> public override TraceListener Assemble(IBuilderContext context, TraceListenerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { FormattedDatabaseTraceListenerData castedObjectConfiguration = (FormattedDatabaseTraceListenerData)objectConfiguration; Data.Database database = (Data.Database)context.HeadOfChain.BuildUp(context, typeof(Data.Database), null, castedObjectConfiguration.DatabaseInstanceName); ILogFormatter formatter = LogFormatterCustomFactory.Instance.Create(context, castedObjectConfiguration.Formatter, configurationSource, reflectionCache); TraceListener createdObject = new FormattedDatabaseTraceListener( database, castedObjectConfiguration.WriteLogStoredProcName, castedObjectConfiguration.AddCategoryStoredProcName, formatter); return(createdObject); }
public void Setup() { listenerData = new RollingFlatFileTraceListenerData( "listener", "file name", "header", "footer", 100, "timestamp pattern", RollFileExistsBehavior.Increment, RollInterval.Day, TraceOptions.DateTime | TraceOptions.Callstack, "formatter") { Filter = SourceLevels.Warning, MaxArchivedFiles = 100 }; }
public void Setup() { listenerData = new MsmqTraceListenerData( "listener", "queue path", "formatter", MessagePriority.High, true, TimeSpan.MinValue, TimeSpan.MaxValue, false, true, false, MessageQueueTransactionType.Automatic) { TraceOutputOptions = TraceOptions.DateTime | TraceOptions.Callstack, Filter = SourceLevels.Warning }; }
public override TraceListener Assemble(IBuilderContext context, TraceListenerData configData, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { RollOnceTraceListenerData rolConfigData = configData as RollOnceTraceListenerData; ILogFormatter formatter = GetFormatter(context, rolConfigData.Formatter, configurationSource, reflectionCache); TraceListener createdObject = new Igt.Adv.Patron.Logging.TraceListeners.RollOnceTraceListener( rolConfigData.Name, rolConfigData.FileName, rolConfigData.Header, rolConfigData.Footer, formatter, rolConfigData.MaxLogs ); return(createdObject); }
/// <summary> /// Adds a new trace listener associated with an unique name and a type containing the implementation. /// </summary> /// <param name="name">The unique name under which a new trace listener will be added to the collection.</param> /// <param name="listenerType">The type implementing the new trace listener.</param> public void AddTraceListener(string name, Type listenerType) { Guard.ArgumentNotNullOrEmptyString(name, "name"); Guard.ArgumentNotNull(listenerType, "listenerType"); ConfigurationElementTypeAttribute configElementTypeAttr = FrameworkUtility.GetDeclarativeAttribute <ConfigurationElementTypeAttribute>(listenerType); if (configElementTypeAttr != null) { TraceListenerData listenerData = Activator.CreateInstance(configElementTypeAttr.ConfigurationType) as TraceListenerData; if (listenerData != null) { listenerData.ListenerDataType = configElementTypeAttr.ConfigurationType; listenerData.Name = name; listenerData.Type = listenerType; this.loggingSettings.TraceListeners.Add(listenerData); } } }
/// <summary> /// Gets the logging output from the app.config (loggingConfiguration section) /// </summary> private static void GetLoggingSettings() { IConfigurationSource configSource = Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationSourceFactory.Create(); LoggingSettings logSettings = LoggingSettings.GetLoggingSettings(configSource); TraceListenerDataCollection dataCollection = logSettings.TraceListeners; if (dataCollection.Count == 0) { return; } TraceListenerData traceListenerData = dataCollection.Get(0); if (traceListenerData is RollingFlatFileTraceListenerData) { RollingFlatFileTraceListenerData tld = (RollingFlatFileTraceListenerData)traceListenerData; loggingOutputFileName = tld.FileName; } }
public override TraceListener Assemble(IBuilderContext context, TraceListenerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { FormattedDatabaseTraceListenerData castedObjectConfiguration = (FormattedDatabaseTraceListenerData)objectConfiguration; IBuilderContext databaseContext = context.CloneForNewBuild( NamedTypeBuildKey.Make <Data.Database>(castedObjectConfiguration.DatabaseInstanceName), null); Data.Database database = (Data.Database)databaseContext.Strategies.ExecuteBuildUp(databaseContext); ILogFormatter formatter = GetFormatter(context, castedObjectConfiguration.Formatter, configurationSource, reflectionCache); TraceListener createdObject = new FormattedDatabaseTraceListener( database, castedObjectConfiguration.WriteLogStoredProcName, castedObjectConfiguration.AddCategoryStoredProcName, formatter); return(createdObject); }
public void Setup() { listenerData = new WmiTraceListenerData("listener"); }
public TraceListenerNodeImpl(TraceListenerData data) { Rename(data.Name); TraceOutputOptions = data.TraceOutputOptions; }
/// <summary> /// Adds a <see cref="TraceListenerData"/> instance to the logging settings and adds a <see cref="TraceListenerReferenceData"/> to the current Category Source. /// </summary> /// <param name="traceListenerData">The <see cref="TraceListenerData"/> that sould be added to configuration.</param> protected void AddTraceListenerToSettingsAndCategory(TraceListenerData traceListenerData) { extensionContext.LoggingSettings.TraceListeners.Add(traceListenerData); extensionContext.CurrentTraceSource.TraceListeners.Add(new TraceListenerReferenceData(traceListenerData.Name)); }
public void TraceListenerWithDisabledPolicyIsNotRemovedIfGroupPoliciesAreDisabled() { MockConfigurationElementManageabilityProvider registeredProvider = new MockConfigurationElementManageabilityProvider(); Dictionary<Type, ConfigurationElementManageabilityProvider> subProviders = new Dictionary<Type, ConfigurationElementManageabilityProvider>(); subProviders.Add(typeof(TraceListenerData), registeredProvider); provider = new LoggingSettingsManageabilityProvider(subProviders); TraceListenerData traceListener1Data = new TraceListenerData(); traceListener1Data.Name = "traceListener1"; section.TraceListeners.Add(traceListener1Data); TraceListenerData traceListener2Data = new TraceListenerData(); traceListener2Data.Name = "traceListener2"; section.TraceListeners.Add(traceListener2Data); MockRegistryKey machineTraceListenersKey = new MockRegistryKey(false); machineKey.AddSubKey(LoggingSettingsManageabilityProvider.TraceListenersKeyName, machineTraceListenersKey); MockRegistryKey machineTraceListener2Key = new MockRegistryKey(false); machineTraceListenersKey.AddSubKey("traceListener2", machineTraceListener2Key); machineTraceListener2Key.AddBooleanValue(AdmContentBuilder.AvailableValueName, false); provider.OverrideWithGroupPolicies(section, false, machineKey, userKey); Assert.AreEqual(2, section.TraceListeners.Count); Assert.IsNotNull(section.TraceListeners.Get("traceListener1")); Assert.IsNotNull(section.TraceListeners.Get("traceListener2")); Assert.IsTrue(MockRegistryKey.CheckAllClosed(machineTraceListenersKey, machineTraceListener2Key)); }
// Methods public override TraceListener Assemble(IBuilderContext context, TraceListenerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache) { RollingFileTraceListenerData data = (RollingFileTraceListenerData)objectConfiguration; return(new RollingFileTraceListener(data.FileName, data.Header, data.Footer, base.GetFormatter(context, data.Formatter, configurationSource, reflectionCache))); }