Пример #1
0
            public static LogWriter ConfigureLogWriter()
            {
                //var textFileFormatter = new TextFormatter();
                var flatFileListener = new RollingFlatFileTraceListener(@"C:\Temp\EntLibLgoFile.log");
                var asynFlatFileTraceListener = new AsynchronousTraceListenerWrapper(flatFileListener, true);

                EventLog ev = new EventLog("Application", ".", "EntLibLogging");
                EventLog eventLog = new EventLog("Application");
                var eventLogListener = new EventLogTraceListener(ev);
                var asyncEventLogListener = new AsynchronousTraceListenerWrapper(eventLogListener, true);

                var loggingConfig = new LoggingConfiguration();
                loggingConfig.AddLogSource("EntLibFlatFileLogging", SourceLevels.All, false, asynFlatFileTraceListener);
                loggingConfig.AddLogSource("EntLibEventLogLogging", SourceLevels.All, false, asyncEventLogListener);
                logWriter = new LogWriter(loggingConfig);
                return logWriter;
            }
        public void TestInitialize()
        {
            this.synchronous = new WrappedTraceListener();
            this.asynchronous = new WrappedTraceListener();
            this.errorListener = new WrappedTraceListener();

            this.logWriter = new LogWriter(new LoggingConfiguration());
            this.logWriter.Configure(c =>
                {
                    var asynchronous = new AsynchronousTraceListenerWrapper(this.asynchronous);

                    c.AddLogSource("synchronous").AddTraceListener(this.synchronous);
                    c.AddLogSource("asynchronous").AddTraceListener(asynchronous);
                    var autoflush = c.AddLogSource("asynchronous-autoflush");
                    autoflush.AddTraceListener(asynchronous);
                    autoflush.AutoFlush = true;
                    var mixed = c.AddLogSource("mixed");
                    mixed.AddTraceListener(this.synchronous);
                    mixed.AddTraceListener(asynchronous);

                    c.SpecialSources.LoggingErrorsAndWarnings.Listeners.Add(this.errorListener);
                });
        }
        /// <summary>
        /// Builds the <see cref="TraceListener" /> object represented by this configuration object.
        /// </summary>
        /// <param name="settings">The logging configuration settings.</param>
        /// <returns>
        /// A trace listener.
        /// </returns>
        public TraceListener BuildTraceListener(LoggingSettings settings)
        {
            Guard.ArgumentNotNull(settings, "settings");

            var listener = this.CoreBuildTraceListener(settings);

            listener.Name = this.Name;
            listener.TraceOutputOptions = this.TraceOutputOptions;

            if (this.Asynchronous)
            {
                listener = 
                    new AsynchronousTraceListenerWrapper(
                        listener, 
                        ownsWrappedTraceListener: true, 
                        bufferSize: this.AsynchronousBufferSize, 
                        maxDegreeOfParallelism: this.AsynchronousMaxDegreeOfParallelism, 
                        disposeTimeout: this.AsynchronousDisposeTimeout);
            }

            if (this.Filter != SourceLevels.All)
            {
                listener.Filter = new EventTypeFilter(this.Filter);
            }

            return listener;
        }
 protected override void Arrange()
 {
     this.wrapped = new DisposableTraceListener();
     this.wrapper = new AsynchronousTraceListenerWrapper(this.wrapped, ownsWrappedTraceListener: false);
 }
 protected override void Arrange()
 {
     this.continueEvent = new SemaphoreSlim(0, 1);
     this.wrappedListener = new WrappedTraceListener(false, this.continueEvent);
     this.wrapper = new AsynchronousTraceListenerWrapper(this.wrappedListener, ownsWrappedTraceListener: false, bufferSize: 10);
 }
        protected override void Arrange()
        {
            this.continueEvent = new SemaphoreSlim(0, 1);
            this.wrappedListener = new WrappedTraceListener(false, this.continueEvent);
            this.wrapper = new AsynchronousTraceListenerWrapper(this.wrappedListener, bufferSize: 10, disposeTimeout: TimeSpan.Zero);

            this.wrapper.TraceData(new TraceEventCache(), "test", TraceEventType.Error, 1, 1);
            this.wrapper.TraceData(new TraceEventCache(), "test", TraceEventType.Error, 2, 2);
            this.wrapper.TraceData(new TraceEventCache(), "test", TraceEventType.Error, 3, 3);
            this.wrapper.TraceData(new TraceEventCache(), "test", TraceEventType.Error, 4, 4);
            this.wrapper.TraceData(new TraceEventCache(), "test", TraceEventType.Error, 5, 5);
            this.wrapper.TraceData(new TraceEventCache(), "test", TraceEventType.Error, 6, 6);
            this.wrapper.TraceData(new TraceEventCache(), "test", TraceEventType.Error, 7, 7);
            this.wrapper.TraceData(new TraceEventCache(), "test", TraceEventType.Error, 8, 8);
        }
 protected override void Arrange()
 {
     this.continueEvent = new SemaphoreSlim(0, 2);
     this.wrappedListener = new WrappedTraceListener(true, this.continueEvent);
     this.wrapper = new AsynchronousTraceListenerWrapper(this.wrappedListener, bufferSize: 10, maxDegreeOfParallelism: 2);
 }