public void CategoriesDataTest() { CategoryDataCollection data = new CategoryDataCollection(); CategoryData categoryData = new CategoryData(); categoryData.Name = "Test"; data.Add(categoryData); CategoryCollectionNode node = new CategoryCollectionNode(data); GeneratedApplicationNode.Nodes.Add(node); CategoryDataCollection nodeData = node.CategoryDataCollection; Assert.AreEqual(1, nodeData.Count); Assert.AreEqual(categoryData.Name, nodeData[categoryData.Name].Name); }
public void DistributorSettingsPropertiesTest() { CategoryData categoryData = new CategoryData(); categoryData.Name = SR.DefaultCategory; CategoryNode defaultCategory = new CategoryNode(categoryData); TextFormatterData formatterData = new TextFormatterData(); formatterData.Name = SR.DefaultFormatter; TextFormatterNode defaultFormatter = new TextFormatterNode(formatterData); DistributorSettingsNode distributorSettings = new DistributorSettingsNode(); applicationNode.Nodes.Add(distributorSettings); distributorSettings.DefaultFormatter = defaultFormatter; distributorSettings.DefaultCategory = defaultCategory; Assert.AreEqual(defaultCategory.Name, distributorSettings.DefaultCategory.Name); Assert.AreEqual(defaultFormatter, distributorSettings.DefaultFormatter); }
private static DistributorSettings GenerateDistributorSettings() { DistributorSettings result = new DistributorSettings(); result.DefaultCategory="AppError" ; result.DefaultFormatter="XmlFormat"; result.DistributorService = new MsmqDistributorServiceData("Enterprise Library Logging Distributor Service", @".\Private$\entlib", 1000 ); result.SinkDataCollection.Add( new CustomSinkData("MockSink", typeof(MockLogSink).AssemblyQualifiedName ) ); result.Formatters.Add( new TextFormatterData("XmlFormat", "<![CDATA[<EntLibLog>{newline}{tab}<message>{message}</message>{newline}{tab}<timestamp>{timestamp}</timestamp>{newline}{tab}<title>{title}</title>{newline}</EntLibLog>]]>")); CategoryData data = new CategoryData(); data.Name = "AppError"; data.DestinationDataCollection.Add( new DestinationData("MockSink", "MockSink")); result.CategoryDataCollection.Add(data); return result; }
/// <devdoc> /// Send the log message to each destination sink for the selected category. /// </devdoc> private void DistributeLogEntry(LogEntry log, CategoryData category) { foreach (DestinationData destination in category.DestinationDataCollection) { try { ILogSink sink = CreateSink(destination.Sink); sink.Formatter = CreateFormatter(destination.Format); sink.SendMessage(log); LoggingLogWrittenEvent.Fire(sink.Formatter.Format(log)); } catch (Exception ex) { this.events.LogSendingMessageException(ex, destination.Sink, log); this.defaulLogSink.SendMessage(log); } } }
/// <summary> /// <para>Adds an <see cref="CategoryData"/> into the collection.</para> /// </summary> /// <param name="categoryData"> /// <para>The <see cref="CategoryData"/> to add. The value can not be a <see langword="null"/> reference (Nothing in Visual Basic).</para> /// </param> /// <remarks> /// <para>If a reference already exists in the collection by <seealso cref="CategoryData.Name"/>, it will be replaced with the new reference.</para> /// </remarks> /// <exception cref="ArgumentNullException"> /// <para><paramref name="categoryData"/> is a <see langword="null"/> reference (Nothing in Visual Basic).</para> /// </exception> /// <exception cref="InvalidOperationException"> /// <para><seealso cref="CategoryData.Name"/> is a <see langword="null"/> reference (Nothing in Visual Basic).</para> /// </exception> public void Add(CategoryData categoryData) { if (categoryData == null) { throw new ArgumentNullException("categoryData"); } if (categoryData.Name == null) { throw new InvalidOperationException(SR.ExceptionDestinationDataName); } BaseAdd(categoryData.Name, categoryData); }
private CategoryNode CreateDefaultNode(string categoryName, string destinationName, string sinkNodeReference) { CategoryData data = new CategoryData(categoryName); DestinationData destination = new DestinationData(destinationName, sinkNodeReference, SR.DefaultFormatter); data.DestinationDataCollection.Add(destination); return new CategoryNode(data); }
/// <summary> /// Creates node with specified configuration data. /// </summary> /// <param name="categoryData">The specified configuration data.</param> public CategoryNode(CategoryData categoryData) : base() { if (categoryData == null) throw new ArgumentNullException("categoryData"); this.categoryData = categoryData; }