当前位置: 首页>>代码示例>>C#>>正文


C# LogWriter.Dispose方法代码示例

本文整理汇总了C#中LogWriter.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# LogWriter.Dispose方法的具体用法?C# LogWriter.Dispose怎么用?C# LogWriter.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LogWriter的用法示例。


在下文中一共展示了LogWriter.Dispose方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanFindMatchingCategories

        public void CanFindMatchingCategories()
        {
            Dictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>();
            traceSources.Add("newcat1", new LogSource("newcat1"));
            traceSources.Add("newcat2", new LogSource("newcat2"));
            traceSources.Add("newcat3", new LogSource("newcat3"));
            traceSources.Add("newcat4", new LogSource("newcat4"));
            LogWriter logWriter = new LogWriter(emptyFilters, traceSources, new LogSource("errors"), "default");

            string[] categories = new string[] { "newcat1", "newcat2", "newcat5", "newcat6" };
            LogEntry logEntry = new LogEntry();
            logEntry.Categories = categories;
            IEnumerable<LogSource> matchingTraceSources = logWriter.GetMatchingTraceSources(logEntry);

            logWriter.Dispose();

            Dictionary<string, LogSource> matchingTraceSourcesDictionary = new Dictionary<string, LogSource>();
            foreach (LogSource traceSource in matchingTraceSources)
            {
                matchingTraceSourcesDictionary.Add(traceSource.Name, traceSource);
            }

            Assert.AreEqual(2, matchingTraceSourcesDictionary.Count);
            Assert.IsTrue(matchingTraceSourcesDictionary.ContainsKey(categories[0]));
            Assert.IsTrue(matchingTraceSourcesDictionary.ContainsKey(categories[1]));
            Assert.IsFalse(matchingTraceSourcesDictionary.ContainsKey(categories[2]));
        }
开发者ID:bnantz,项目名称:NCS-V2-0,代码行数:27,代码来源:LogDistributorFixture.cs

示例2: MissingCategoriesWarningIsLoggedIfLogWarningFlagIsTrue

	    public void MissingCategoriesWarningIsLoggedIfLogWarningFlagIsTrue()
	    {
	        LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
	        errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());

	        LogSource failingTraceSource = new LogSource("logging", SourceLevels.All);
	        failingTraceSource.Listeners.Add(new MockTraceListener());
	        LogSource loggingTraceSource = new LogSource("logging2", SourceLevels.All);
	        loggingTraceSource.Listeners.Add(new MockTraceListener());

	        LogWriter writer =
	            new LogWriter(new ILogFilter[0],
	                          new LogSource[] { failingTraceSource, loggingTraceSource },
	                          emptyTraceSource,
	                          emptyTraceSource,
	                          errorsTraceSource,
	                          "default",
	                          false,
	                          true);

	        LogEntry logEntry = new LogEntry();
	        logEntry.Message = originalMessage;
	        logEntry.Severity = TraceEventType.Critical;
	        logEntry.Categories = new string[] { "logging", "logging2", "logging3" };

	        writer.Write(logEntry);

            writer.Dispose();
            Assert.AreEqual(1, ErrorsMockTraceListener.Entries.Count);
	        Assert.AreEqual(TraceEventType.Error, ErrorsMockTraceListener.LastEntry.Severity);
	        Assert.IsTrue(MatchTemplate(ErrorsMockTraceListener.LastEntry.Message, Resources.MissingCategories));
	        Assert.AreEqual(2, MockTraceListener.Entries.Count);
	        Assert.AreSame(logEntry, MockTraceListener.LastEntry);
	    }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:34,代码来源:LogDistributorFixture.cs

示例3: NoErrorsWhileSendingToTraceSourceOnlyLogsOriginalMessageToCategoryTraceSources

	    public void NoErrorsWhileSendingToTraceSourceOnlyLogsOriginalMessageToCategoryTraceSources()
	    {
	        LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
	        errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());

	        LogSource failingTraceSource = new LogSource("logging", SourceLevels.All);
	        failingTraceSource.Listeners.Add(new MockTraceListener());
	        LogSource loggingTraceSource = new LogSource("logging2", SourceLevels.All);
	        loggingTraceSource.Listeners.Add(new MockTraceListener());

	        LogWriter writer =
	            new LogWriter(new ILogFilter[0],
	                          new LogSource[] { failingTraceSource, loggingTraceSource },
	                          errorsTraceSource,
	                          "default");

	        LogEntry logEntry = new LogEntry();
	        logEntry.Message = originalMessage;
	        logEntry.Severity = TraceEventType.Critical;
	        logEntry.Categories = new string[] { "logging", "logging2" };

	        writer.Write(logEntry);

            writer.Dispose();
            Assert.AreEqual(0, ErrorsMockTraceListener.Entries.Count);
	        Assert.AreEqual(2, MockTraceListener.Entries.Count);
	        Assert.AreSame(logEntry, MockTraceListener.LastEntry);
	    }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:28,代码来源:LogDistributorFixture.cs

示例4: ErrorWhileSendingToTraceSourceLogsWarningAndLogsOriginalMessageToNonFailingTraceSources

	    public void ErrorWhileSendingToTraceSourceLogsWarningAndLogsOriginalMessageToNonFailingTraceSources()
	    {
	        LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
	        errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());

	        LogSource failingTraceSource = new LogSource("failing", SourceLevels.All);
	        failingTraceSource.Listeners.Add(new ExceptionThrowingMockTraceListener());
	        LogSource loggingTraceSource = new LogSource("logging", SourceLevels.All);
	        loggingTraceSource.Listeners.Add(new MockTraceListener());

	        LogWriter writer =
	            new LogWriter(new ILogFilter[0],
	                          new LogSource[] { failingTraceSource, loggingTraceSource },
	                          errorsTraceSource,
	                          "default");

	        LogEntry logEntry = new LogEntry();
	        logEntry.Message = originalMessage;
	        logEntry.Severity = TraceEventType.Critical;
	        logEntry.Categories = new string[] { "failing", "logging" };

	        writer.Write(logEntry);

            writer.Dispose();
            Assert.AreEqual(1, ErrorsMockTraceListener.Entries.Count);
	        Assert.AreEqual(TraceEventType.Error, ErrorsMockTraceListener.LastEntry.Severity);
	        Assert.IsTrue(MatchTemplate(ErrorsMockTraceListener.LastEntry.Message, Resources.TraceSourceFailed));
	        Assert.AreEqual(1, MockTraceListener.Entries.Count);
	        Assert.AreSame(logEntry, MockTraceListener.LastEntry);
	    }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:30,代码来源:LogDistributorFixture.cs

示例5: UsesDefaultTraceSourceIfThereAreMissingCategoriesAndDefaultIsConfiguredAndMandatoryIsNotConfigured

	    public void UsesDefaultTraceSourceIfThereAreMissingCategoriesAndDefaultIsConfiguredAndMandatoryIsNotConfigured()
	    {
	        Dictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>();
	        traceSources.Add("newcat1", new LogSource("newcat1"));
	        traceSources.Add("newcat2", new LogSource("newcat2"));
	        traceSources.Add("newcat3", new LogSource("newcat3"));
	        traceSources.Add("newcat4", new LogSource("newcat4"));
	        LogSource mandatoryTraceSource = null;
	        LogSource defaultTraceSource = new LogSource("default");
	        LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
	        errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());
	        LogWriter logWriter =
	            new LogWriter(emptyFilters, traceSources, mandatoryTraceSource, defaultTraceSource, errorsTraceSource, "default", false, false);

	        string[] categories = new string[] { "newcat1", "newcat2", "newcat5", "newcat6" };
	        LogEntry logEntry = new LogEntry();
	        logEntry.Categories = categories;
	        IEnumerable<LogSource> matchingTraceSources = logWriter.GetMatchingTraceSources(logEntry);

            logWriter.Dispose();
            Dictionary<string, LogSource> matchingTraceSourcesDictionary = new Dictionary<string, LogSource>();
	        foreach (LogSource traceSource in matchingTraceSources)
	        {
	            matchingTraceSourcesDictionary.Add(traceSource.Name, traceSource);
	        }

	        Assert.AreEqual(3, matchingTraceSourcesDictionary.Count);
	        Assert.IsTrue(matchingTraceSourcesDictionary.ContainsKey(categories[0]));
	        Assert.IsTrue(matchingTraceSourcesDictionary.ContainsKey(categories[1]));
	        Assert.IsTrue(matchingTraceSourcesDictionary.ContainsKey(defaultTraceSource.Name));
	        Assert.AreEqual(0, ErrorsMockTraceListener.Entries.Count);
	    }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:32,代码来源:LogDistributorFixture.cs

示例6: DoesNotReportMissingCategoriesWhenThereAreNotMissingCategoriesAndDefaultIsNotConfigured

	    public void DoesNotReportMissingCategoriesWhenThereAreNotMissingCategoriesAndDefaultIsNotConfigured()
	    {
	        Dictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>();
	        traceSources.Add("newcat1", new LogSource("newcat1"));
	        traceSources.Add("newcat2", new LogSource("newcat2"));
	        traceSources.Add("newcat3", new LogSource("newcat3"));
	        traceSources.Add("newcat4", new LogSource("newcat4"));
	        LogSource errorsTraceSource = new LogSource("errors", SourceLevels.All);
	        errorsTraceSource.Listeners.Add(new ErrorsMockTraceListener());
	        LogWriter logWriter = new LogWriter(emptyFilters, traceSources, emptyTraceSource, emptyTraceSource, errorsTraceSource, "default", false, false);

	        string[] categories = new string[] { "newcat1", "newcat2" };
	        LogEntry logEntry = new LogEntry();
	        logEntry.Categories = categories;
	        IEnumerable<LogSource> matchingTraceSources = logWriter.GetMatchingTraceSources(logEntry);

            logWriter.Dispose();
            Dictionary<string, LogSource> matchingTraceSourcesDictionary = new Dictionary<string, LogSource>();
	        foreach (LogSource traceSource in matchingTraceSources)
	        {
	            matchingTraceSourcesDictionary.Add(traceSource.Name, traceSource);
	        }

	        Assert.AreEqual(2, matchingTraceSourcesDictionary.Count);
	        Assert.AreEqual(0, ErrorsMockTraceListener.Entries.Count);
	    }
开发者ID:ChiangHanLung,项目名称:PIC_VDS,代码行数:26,代码来源:LogDistributorFixture.cs

示例7: DisposingWriterThrowsObjectDisposedExceptionWhenUsed

        public void DisposingWriterThrowsObjectDisposedExceptionWhenUsed()
        {
            var writer = new LogWriter(new LoggingConfiguration());
            writer.Dispose();

            AssertEx.Throws<ObjectDisposedException>(() => writer.Write("Should throw."));
        }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:7,代码来源:LogWriterFixture.cs

示例8: DisposingWriterDisposesAllTraceListenersOnce

        public void DisposingWriterDisposesAllTraceListenersOnce()
        {
            var traceListener = new MockDisposableTraceListener();

            var config = new LoggingConfiguration();
            config.AddLogSource("cat1", traceListener);
            config.AddLogSource("cat2", traceListener);
            config.SpecialSources.AllEvents.Listeners.Add(traceListener);

            var logWriter = new LogWriter(config);
            logWriter.Dispose();

            Assert.AreEqual(1, traceListener.DisposedCalls);
        }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:14,代码来源:LogWriterFixture.cs

示例9: UsedMandatoryTraceSourceIfAllCategoriesAreMissing

        public void UsedMandatoryTraceSourceIfAllCategoriesAreMissing()
        {
            Dictionary<string, LogSource> traceSources = new Dictionary<string, LogSource>();
            traceSources.Add("newcat1", new LogSource("newcat1"));
            traceSources.Add("newcat2", new LogSource("newcat2"));
            traceSources.Add("newcat3", new LogSource("newcat3"));
            traceSources.Add("newcat4", new LogSource("newcat4"));
            LogSource mandatoryTraceSource = new LogSource("mandatory");
            LogSource errorsTraceSource = new LogSource("errors", new[] { new ErrorsMockTraceListener() }, SourceLevels.All);
            LogWriter logWriter = new LogWriter(emptyFilters, traceSources, mandatoryTraceSource, emptyTraceSource, errorsTraceSource, "default", false, false);

            string[] categories = new string[] { "newcat5", "newcat6" };
            LogEntry logEntry = new LogEntry();
            logEntry.Categories = categories;
            IEnumerable<LogSource> matchingTraceSources = logWriter.GetMatchingTraceSources(logEntry);

            logWriter.Dispose();
            Dictionary<string, LogSource> matchingTraceSourcesDictionary = new Dictionary<string, LogSource>();
            foreach (LogSource traceSource in matchingTraceSources)
            {
                matchingTraceSourcesDictionary.Add(traceSource.Name, traceSource);
            }

            Assert.AreEqual(1, matchingTraceSourcesDictionary.Count);
            Assert.IsTrue(matchingTraceSourcesDictionary.ContainsKey(mandatoryTraceSource.Name));
            Assert.AreEqual(0, ErrorsMockTraceListener.Entries.Count);
        }
开发者ID:HondaBey,项目名称:EnterpriseLibrary6,代码行数:27,代码来源:LogDistributorFixture.cs


注:本文中的LogWriter.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。