public void ConfigurationChangeNotificationTriggersLogWriterStructureHolderUpdate()
        {
            LogWriter logWriter = new LogWriterFactory(configurationSource).Create();
            Assert.IsNotNull(logWriter);

            {
                Assert.AreEqual(2, logWriter.TraceSources.Count);
                IEnumerator<LogSource> sources = logWriter.TraceSources.Values.GetEnumerator();
                sources.MoveNext();
                Assert.AreEqual("blocking", sources.Current.Name);
            }

            settings.TraceSources.Get(0).Name = "new source";

            Thread notificationThread = new Thread(FireConfigurationSourceChangedNotification);
            notificationThread.Start(new string[] { LoggingSettings.SectionName });
            notificationThread.Join(400);

            {
                Assert.AreEqual(2, logWriter.TraceSources.Count);
                IEnumerator<LogSource> sources = logWriter.TraceSources.Values.GetEnumerator();
                sources.MoveNext();
                Assert.AreEqual("new source", sources.Current.Name);
            }
        }
Ejemplo n.º 2
0
        public void Initialize()
        {
            this.configurationSource = new FileConfigurationSource(@"configurations\\LoggingExceptionHandler.config");

            LogWriterFactory factory = new LogWriterFactory((e) => { return(this.configurationSource.GetSection(e)); });
            LogWriter        writer  = factory.Create();

            Logger.SetLogWriter(writer);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 private ClosedLoopLogFilter(
     LogWriterFactory factory,
     Parameter parameter,
     Conversion conversion)
     : base(
         factory,
         parameter,
         conversion)
 {
 }
Ejemplo n.º 4
0
 internal TrivialLogFilter(
     LogWriterFactory factory,
     bool state)
     : base(
         factory,
         null,
         null)
 {
     this.state = state;
 }
Ejemplo n.º 5
0
        public static void SetLogWriterFactory()
        {
            //this should not be necessary but this will prevent from the following error on some systems:
            //"The type Database cannot be constructed. You must configure the container to supply this value."
            DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory());
            IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
            LogWriterFactory     logWriterFactory    = new LogWriterFactory(configurationSource);

            Microsoft.Practices.EnterpriseLibrary.Logging.Logger.SetLogWriter(logWriterFactory.Create());
        }
Ejemplo n.º 6
0
        public static void UseDefaultConfig()
        {
            var path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Default.config");

            File.WriteAllText(path, Resources.Res.Default);
            var factory = new LogWriterFactory(new FileConfigurationSource(path));

            Logger.SetLogWriter(factory.Create());
            _writer = Logger.Writer;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Constructor
 /// </summary>
 private KnockLogFilter(
     LogWriterFactory factory,
     Parameter parameter,
     Conversion conversion)
     : base(
         factory,
         parameter,
         conversion)
 {
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Constructor
 /// </summary>
 private FullThrottleLogFilter(
     LogWriterFactory factory,
     Parameter parameter,
     Conversion conversion)
     : base(
         factory,
         parameter,
         conversion)
 {
 }
        public void DifferentLogWriterFactoryReturnsDifferentInstance()
        {
            LogWriterFactory factory = new LogWriterFactory();

            createdObject1 = factory.Create();
            factory        = new LogWriterFactory();
            createdObject2 = factory.Create();
            Assert.IsNotNull(createdObject1);
            Assert.IsFalse(object.ReferenceEquals(createdObject1, createdObject2));
        }
        public void Initialize()
        {
            var logWriter =
#if NETCOREAPP
                new LogWriterFactory(NetCoreHelper.LookupConfigSection).Create();
#else
                new LogWriterFactory().Create();
#endif
            Logger.SetLogWriter(logWriter, false);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Protected constructor.  Use the factory method instead
 /// </summary>
 internal LogFilter(
     LogWriterFactory factory,
     Parameter parameter,
     Conversion conversion)
 {
     this.factory    = factory;
     this.parameter  = parameter;
     this.conversion = conversion;
     this.queue      = new Queue <ILogRow>(extraRows);
 }
Ejemplo n.º 12
0
        // This method gets called by the runtime. Use this method to add services to the container
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddCors(
                options => options.AddPolicy("AllowCors", builder =>
            {
                builder
                .AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials();
            }));

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddMvc().AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver =
                    new CamelCasePropertyNamesContractResolver();
            });

            LogWriterFactory log       = new LogWriterFactory();
            LogWriter        logWriter = log.Create();

            Logger.SetLogWriter(logWriter, false);

            //---Adding scope for all classes
            services.AddSingleton <ILoggingHelper, LoggingHelper>(serviceProvider =>
            {
                return(new LoggingHelper(logWriter));
            });

            services.AddSingleton <IExceptionHelper, ExceptionHelper>(serviceProvider =>
            {
                return(new ExceptionHelper(logWriter));
            });

            // Register Infrastructure
            services.AddScoped <IDatabaseFactory <PostalAddressDBContext>, DatabaseFactory <PostalAddressDBContext> >();

            // Register DataServices
            services.AddScoped <IPostalAddressDataService, PostalAddressDataService>();

            // Register Integration Services
            services.AddScoped <IPostalAddressIntegrationService, PostalAddressIntegrationService>();

            // Register Business Service
            services.AddScoped <IPostalAddressBusinessService, PostalAddressBusinessService>();

            // Others - Helper, Utils etc
            services.AddScoped <IConfigurationHelper, ConfigurationHelper>();
            services.AddScoped <IHttpHandler, HttpHandler>();
        }
Ejemplo n.º 13
0
        private LogService()
        {
            DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory());

            IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
            LogWriterFactory     logWriterFactory    = new LogWriterFactory(configurationSource);

            _writer = logWriterFactory.Create();

            Logger.SetLogWriter(_writer);
        }
Ejemplo n.º 14
0
        private LogWriter GetWriter()
        {
            //per http://growingtech.blogspot.it/2013/05/enterprise-library-60-logwriter-has-not.html
            //  we have to explicitly set the writer for EntLib6 before we can return it
            var configurationSource = ConfigurationSourceFactory.Create();
            var logWriterFactory    = new LogWriterFactory(configurationSource);

            Logger.SetLogWriter(logWriterFactory.Create());

            return(Logger.Writer);
        }
Ejemplo n.º 15
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            // Add framework services.
            services.AddApplicationInsightsTelemetry(Configuration);

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddCors(
                options => options.AddPolicy("AllowCors", builder =>
            {
                builder
                .AllowAnyOrigin()
                .AllowAnyMethod()
                .AllowAnyHeader()
                .AllowCredentials();
            }));

            // Add framework services.
            services.AddMvc().AddJsonOptions(options =>
            {
                options.SerializerSettings.ContractResolver =
                    new CamelCasePropertyNamesContractResolver();
            });

            LogWriterFactory log       = new LogWriterFactory();
            LogWriter        logWriter = log.Create();

            Logger.SetLogWriter(logWriter, false);

            //---Adding scope for all classes
            services.AddSingleton <ILoggingHelper, LoggingHelper>(serviceProvider =>
            {
                return(new LoggingHelper(logWriter));
            });

            services.AddSingleton <IExceptionHelper, ExceptionHelper>(serviceProvider =>
            {
                return(new ExceptionHelper(logWriter));
            });

            // Infrastructure
            services.AddTransient <IDatabaseFactory <ReferenceDataDBContext>, DatabaseFactory <ReferenceDataDBContext> >();

            //---Adding scope for all classes
            services.AddScoped <IReferenceDataBusinessService, ReferenceDataBusinessService>();
            services.AddScoped <DataService.Interface.IReferenceDataDataService, DataService.ReferenceDataDataService>();
            services.AddScoped <IActionManagerDataService, ActionManagerDataService>();
            services.AddScoped <IUserRoleUnitDataService, UserRoleUnitDataService>();
            services.AddScoped <IConfigurationHelper, ConfigurationHelper>();
            var physicalProvider = hostingEnvironment.ContentRootFileProvider;
            var embeddedProvider = new EmbeddedFileProvider(Assembly.GetEntryAssembly());

            services.AddSingleton <IFileProvider>(embeddedProvider);
        }
        public void EntryIsWrittenWhenMinMSMQTraceListener()
        {
            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration57"));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);

            var entry = LogEntryFactory.GetLogEntry();

            this.writer.Write(entry);
        }
        public void DifferentLogWriterFactoryReturnsDifferentInstance()
        {
            LogWriterFactory factory = new LogWriterFactory();
            createdObject1 = factory.Create();

            factory = new LogWriterFactory();
            createdObject2 = factory.Create();

            Assert.IsNotNull(createdObject1);
            Assert.IsFalse(object.ReferenceEquals(createdObject1, createdObject2));
        }
Ejemplo n.º 18
0
        public mainForm()
        {
            try
            {
                IConfigurationSource configSource = ConfigurationSourceFactory.Create();
                LogWriterFactory     lwFactory    = new LogWriterFactory(configSource);
                Logger.SetLogWriter(lwFactory.Create(), false);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("Failed to set logger. {0}", ex.Message));
            }
            InitializeComponent();

            //Initialize background worker
            this.bw = new BackgroundWorker();
            this.bw.WorkerSupportsCancellation = true;
            this.bw.WorkerReportsProgress      = true;
            this.bw.DoWork             += this.bw_DoWork;
            this.bw.ProgressChanged    += this.bw_ProgressChanged;
            this.bw.RunWorkerCompleted += this.bw_Complete;

            //Create menu strip gradient fill
            this.menuStrip_Main.Renderer = new TStripRenderer(new ProColorsTable()
            {
                MStripGradientBegin = Color.LightSkyBlue, MStripGradientEnd = Color.DarkSlateBlue
            })
            {
                RoundedEdges = false
            };

            //Set objectlistview header style and hot item style
            var hfs = new BrightIdeasSoftware.HeaderFormatStyle();

            hfs.SetFont(Font = new Font("Arial", 11F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0))));
            hfs.Normal       = new BrightIdeasSoftware.HeaderStateStyle()
            {
                BackColor = Color.FromArgb(76, 74, 132), ForeColor = Color.WhiteSmoke, FrameColor = Color.Black, FrameWidth = 1F
            };
            hfs.Hot = new BrightIdeasSoftware.HeaderStateStyle()
            {
                BackColor = Color.FromArgb(76, 74, 132), ForeColor = Color.WhiteSmoke, FrameColor = Color.Yellow, FrameWidth = 2F
            };

            this.objectListView_Results.HeaderFormatStyle = hfs;

            var rbd = new BrightIdeasSoftware.RowBorderDecoration();

            rbd.BorderPen      = new Pen(Color.FromArgb(128, Color.LightSeaGreen), 2);
            rbd.BoundsPadding  = new Size(1, 1);
            rbd.CornerRounding = 4.0f;

            this.objectListView_Results.HotItemStyle.Decoration = rbd;
        }
Ejemplo n.º 19
0
 public static void Shutdown()
 {
     lock (_locker)
     {
         if (_logWriterFactory != null)
         {
             _logWriterFactory.Shutdown();
             _logWriterFactory = null;
         }
     }
 }
Ejemplo n.º 20
0
 public static void Shutdown()
 {
     lock (_locker)
     {
         if (_logger != null)
         {
             _logger.Shutdown();
             _logger = null;
         }
     }
 }
Ejemplo n.º 21
0
 protected override ILoggerInventory CreateLoggerInventory()
 {
     return(new LoggerInventory <LogWriter>(
                (name) => GetRepositoryConfigFile(name),
                (name, file) =>
     {
         var factory = new LogWriterFactory(new FileConfigurationSource(file));
         return factory.Create();
     },
                (resp, name) => new EnterpriseLibraryLogger(resp, name)));
 }
Ejemplo n.º 22
0
        static void Main()
        {
            IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
            LogWriterFactory     logWriterFactory    = new LogWriterFactory(configurationSource);

            Logger.SetLogWriter(logWriterFactory.Create());

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
Ejemplo n.º 23
0
        static SuperLogger()
        {
            var path = @".\";
            //if (!Directory.Exists(path))
            //    path = UtilityMethods.GetCommonPath();

            var configSource     = new FileConfigurationSource(Path.Combine(path, "EntLib.config"));
            var logWriterFactory = new LogWriterFactory(configSource);

            logWriter = logWriterFactory.Create();
        }
        public void LogWriterCreatedThroughFactoryRegistersHandler()
        {
            Assert.AreEqual(0, configurationSource.GetNotificationDelegates(LoggingSettings.SectionName).Length);

            LogWriter logWriter = new LogWriterFactory(configurationSource).Create();

            Assert.IsNotNull(logWriter);
            Assert.AreEqual(2, logWriter.TraceSources.Count);

            Assert.AreEqual(1, configurationSource.GetNotificationDelegates(LoggingSettings.SectionName).Length);
        }
Ejemplo n.º 25
0
 public Log()
 {
     //Intialize the log configuration
     if (!_isInitialized)
     {
         var config           = ConfigurationSourceFactory.Create();
         var logWriterFactory = new LogWriterFactory(config);
         Logger.SetLogWriter(logWriterFactory.Create());
         _isInitialized = true;
     }
 }
        protected void Application_Start(object sender, EventArgs e)
        {
            IConfigurationSource source = ConfigurationSourceFactory.Create();

            var logwriterFactory = new LogWriterFactory(source);
            var logWriter = logwriterFactory.Create();
            Logger.SetLogWriter(logWriter);

            var exceptionPolicyFactory = new ExceptionPolicyFactory(source);
            var exceptionManager = exceptionPolicyFactory.CreateManager();
            ExceptionPolicy.SetExceptionManager(exceptionManager);
        }
Ejemplo n.º 27
0
        private void Application_Error(object sender, EventArgs e)
        {
            HttpContext     ctx         = HttpContext.Current;
            HttpRequest     request     = ctx.Request;
            HttpApplication application = (HttpApplication)sender;
            Exception       ex          = application.Server.GetLastError().GetBaseException();

            // Use log write factory to load from app.config
            LogWriterFactory logWriterFactory = new LogWriterFactory();

            // Create the LogWrite instance
            LogWriter logWriter = logWriterFactory.Create();

            // Create debug provider
            var extendedInfo = new Dictionary <string, object>();
            var debug        = new DebugInformationProvider();

            debug.PopulateDictionary(extendedInfo);

            // Create the Log Entry
            var logEntry = new LogEntry
            {
                Message    = "This is an error message",
                Categories = new List <string> {
                    "Debug"
                },
                ExtendedProperties = extendedInfo
            };

            // Prepare the trace manager
            TraceManager traceManager = new TraceManager(logWriter);

            // Log
            // checking app.config "tracingEnabled" - <loggingConfiguration name="" tracingEnabled="true">
            if (logWriter.IsLoggingEnabled())
            {
                logWriter.Write("This is a Demo log message", "Demo");
                logWriter.Write("This is an application error", "Error");
                logWriter.Write("This is a general log message");

                using (traceManager.StartTrace("Debug"))
                {
                    logWriter.Write(logEntry);
                }
            }

            ExceptionPolicy.HandleException(ex, "GlobalExceptionLogger");
            ctx.Server.ClearError();

            ctx.Response.Write(Logger.IsLoggingEnabled());
            ctx.Response.Write(Logger.ShouldLog(logEntry));
            ctx.Response.Write(logEntry.Categories.Contains("Debug"));
        }
Ejemplo n.º 28
0
        public override void Load()
        {
            Bind <IHttpHandler>().To <HttpHandler>();
            LogWriterFactory log       = new LogWriterFactory();
            LogWriter        logWriter = log.Create();

            Logger.SetLogWriter(logWriter, false);

            Bind <ILoggingHelper>().To <LoggingHelper>().InSingletonScope().WithConstructorArgument <LogWriter>(logWriter);
            Bind <IExceptionHelper>().To <ExceptionHelper>().InSingletonScope().WithConstructorArgument <LogWriter>(logWriter);
            Bind <IConfigurationHelper>().To <ConfigurationHelper>().InSingletonScope();
        }
Ejemplo n.º 29
0
        public void EntryIsWrittenWhenSpecialCategoriesCriticalEventLogMax()
        {
            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration76"));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);
            var entry = LogEntryFactory.GetLogEntry();

            this.writer.Write(entry);

            Assert.IsTrue(this.CheckForEntryInEventlog("Message: Sample Message."));
        }
Ejemplo n.º 30
0
        public void SetUp()
        {
            AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);
            var logWriter =
#if NETCOREAPP
                new LogWriterFactory(NetCoreHelper.LookupConfigSection).Create();
#else
                new LogWriterFactory().Create();
#endif
            Logger.SetLogWriter(logWriter, false);
            MockTraceListener.Reset();
        }
Ejemplo n.º 31
0
        public void EntryIsWrittenWhenUnprocessedCategoryEventLog()
        {
            var entry = LogEntryFactory.GetLogEntry();

            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration92"));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);
            this.writer.Write(entry);

            Assert.IsTrue(this.CheckForEntryInEventlog("Message: Sample Message."));
        }
Ejemplo n.º 32
0
 private TestLogFilter(
     LogWriterFactory factory,
     Parameter parameter,
     Conversion conversion,
     string requiredValue)
     : base(
         factory,
         parameter,
         conversion)
 {
     this.requiredValue = requiredValue;
 }
		public void LogWriterCreatedThroughFactoryRegistersHandler()
		{
			Assert.AreEqual(0, configurationSource.GetNotificationDelegates(LoggingSettings.SectionName).Length);

			LogWriter logWriter = new LogWriterFactory(configurationSource).Create();
			Assert.IsNotNull(logWriter);
			Assert.AreEqual(2, logWriter.TraceSources.Count);

			Assert.AreEqual(1, configurationSource.GetNotificationDelegates(LoggingSettings.SectionName).Length);
		}
		// depends on timing
		public void FailureToAcquireWriteLockLogsException()
		{
			LogWriter.SetLockTimeouts(150, 150);

			LogWriter logWriter = new LogWriterFactory(configurationSource).Create();
			Assert.IsNotNull(logWriter);

			Thread blockingLogThread1 = new Thread(new MultiThreadLoggingHelper(logWriter, "blocking").DoLogging);
			Thread notificationThread = new Thread(FireConfigurationSectionChangedNotification);

			try
			{
				MockBlockingCustomTraceListener.waitOnDispose = true;

				// block whild holding writer lock 
				blockingLogThread1.Start();
				for (int i = 0; i < 10; i++)
				{
					Thread.Sleep(10);
					if (MockBlockingCustomTraceListener.PendingTraceRequests == 1) break;
				}
				Assert.AreEqual(1, MockBlockingCustomTraceListener.PendingTraceRequests, "there should be one pending dispose request");

				// try to update
				notificationThread.Start();
				Thread.Sleep(400);
				notificationThread.Join(50);

				using (EventLog applicationLog = new EventLog("Application"))
				{
					EventLogEntry lastEntry = applicationLog.Entries[applicationLog.Entries.Count - 1];

					Assert.AreEqual("Enterprise Library Logging", lastEntry.Source);
					Assert.IsTrue(lastEntry.Message.Contains(Resources.ExceptionFailedToAcquireLockToUpdate));
				}

				// let the trace finish
				lock (MockBlockingCustomTraceListener.traceRequestMonitor)
				{
					Monitor.PulseAll(MockBlockingCustomTraceListener.traceRequestMonitor);
				}
				for (int i = 0; i < 10; i++)
				{
					Thread.Sleep(10);
					if (MockBlockingCustomTraceListener.PendingTraceRequests == 0) break;
				}
				Assert.AreEqual(0, MockBlockingCustomTraceListener.PendingTraceRequests, "there should be no pending trace requests");
			}
			finally
			{
				try { blockingLogThread1.Join(50); }
				catch { }
				try { notificationThread.Join(50); }
				catch { }
			}
		}
		// depends on timing
		public void ChangeNotificationDuringTracingDelaysUpdate()
		{
			LogWriter logWriter = new LogWriterFactory(configurationSource).Create();
			Assert.IsNotNull(logWriter);

			Thread blockingLogThread1 = new Thread(new MultiThreadLoggingHelper(logWriter, "blocking").DoLogging);
			Thread blockingLogThread2 = new Thread(new MultiThreadLoggingHelper(logWriter, "blocking").DoLogging);
			Thread blockingLogThread3 = new Thread(new MultiThreadLoggingHelper(logWriter, "blocking").DoLogging);
			Thread notificationThread = new Thread(FireConfigurationSectionChangedNotification);

			try
			{
				blockingLogThread1.Start();
				for (int i = 0; i < 10; i++)
				{
					Thread.Sleep(10);
					if (MockBlockingCustomTraceListener.PendingTraceRequests == 1) break;
				}

				Assert.AreEqual(0, MockBlockingCustomTraceListener.ProcessedTraceRequests, "there should have been no written entries so far");
				Assert.AreEqual(1, MockBlockingCustomTraceListener.PendingTraceRequests, "the first request should have made it through");

				blockingLogThread2.Start();
				for (int i = 0; i < 10; i++)
				{
					Thread.Sleep(10);
					if (MockBlockingCustomTraceListener.PendingTraceRequests == 2) break;
				}

				Assert.AreEqual(0, MockBlockingCustomTraceListener.ProcessedTraceRequests, "there should have been no written entries so far");
				Assert.AreEqual(2, MockBlockingCustomTraceListener.PendingTraceRequests, "the second request should have made it through");

				notificationThread.Start();
				Thread.Sleep(100);

				Assert.AreEqual(0, MockBlockingCustomTraceListener.ProcessedTraceRequests, "there should have been no written entries so far");
				Assert.AreEqual(2, MockBlockingCustomTraceListener.PendingTraceRequests, "the two requests should still be waiting");

				blockingLogThread3.Start();
				Thread.Sleep(100);

				Assert.AreEqual(0, MockBlockingCustomTraceListener.ProcessedTraceRequests, "there should have been no written entries so far");
				Assert.AreEqual(2, MockBlockingCustomTraceListener.PendingTraceRequests, "the third request should have been delayed by the udpate request");

				lock (MockBlockingCustomTraceListener.traceRequestMonitor)
				{
					Monitor.PulseAll(MockBlockingCustomTraceListener.traceRequestMonitor);
				}
				for (int i = 0; i < 10; i++)
				{
					Thread.Sleep(10);
					if (MockBlockingCustomTraceListener.PendingTraceRequests == 1 &&
						MockBlockingCustomTraceListener.ProcessedTraceRequests == 2)
					{
						break;
					}
				}

				Assert.AreEqual(2, MockBlockingCustomTraceListener.ProcessedTraceRequests, "the two initial requests should have been written");
				Assert.AreEqual(1, MockBlockingCustomTraceListener.PendingTraceRequests, "the third request should have made it through");

				lock (MockBlockingCustomTraceListener.traceRequestMonitor)
				{
					Monitor.PulseAll(MockBlockingCustomTraceListener.traceRequestMonitor);
				}
				for (int i = 0; i < 10; i++)
				{
					Thread.Sleep(10);
					if (MockBlockingCustomTraceListener.PendingTraceRequests == 0) break;
				}

				Assert.AreEqual(3, MockBlockingCustomTraceListener.ProcessedTraceRequests, "all three requests should have been written");
				Assert.AreEqual(0, MockBlockingCustomTraceListener.PendingTraceRequests, "there should be no pending requests");

				Assert.IsTrue(
					object.ReferenceEquals(MockBlockingCustomTraceListener.Instances[0], MockBlockingCustomTraceListener.Instances[1]),
					"the two first requests shared the same listener instance");
				Assert.IsFalse(
					object.ReferenceEquals(MockBlockingCustomTraceListener.Instances[0], MockBlockingCustomTraceListener.Instances[2]),
					"the third request used a new listener instance, after the configuration change");
				Assert.IsTrue(MockBlockingCustomTraceListener.Instances[0].disposeCalled);
				Assert.IsFalse(MockBlockingCustomTraceListener.Instances[2].disposeCalled);
			}
			finally
			{
				try { blockingLogThread1.Join(50); }
				catch { }
				try { blockingLogThread2.Join(50); }
				catch { }
				try { blockingLogThread3.Join(50); }
				catch { }
				try { notificationThread.Join(50); }
				catch { }
			}
		}
		// depends on timing
		public void MultipleConcurrentLoggingRequestsSucceed()
		{
			LogWriter logWriter = new LogWriterFactory(configurationSource).Create();
			Assert.IsNotNull(logWriter);

			Thread blockingLogThread = new Thread(new MultiThreadLoggingHelper(logWriter, "blocking").DoLogging);
			Thread nonblockingLogThread = new Thread(new MultiThreadLoggingHelper(logWriter, "nonblocking").DoLogging);

			try
			{
				blockingLogThread.Start();
				for (int i = 0; i < 10; i++)
				{
					Thread.Sleep(10);
					if (MockBlockingCustomTraceListener.PendingTraceRequests == 1) break;
				}

				Assert.AreEqual(0, MockBlockingCustomTraceListener.ProcessedTraceRequests, "there should have been no written entries so far");
				Assert.AreEqual(1, MockBlockingCustomTraceListener.PendingTraceRequests, "there should be one pending request");
				Assert.AreEqual(0, MockTraceListener.ProcessedTraceRequests);

				nonblockingLogThread.Start();
				for (int i = 0; i < 10; i++)
				{
					Thread.Sleep(10);
					if (MockTraceListener.ProcessedTraceRequests == 1) break;
				}

				Assert.AreEqual(0, MockBlockingCustomTraceListener.ProcessedTraceRequests, "there should have been no written entries so far");
				Assert.AreEqual(1, MockBlockingCustomTraceListener.PendingTraceRequests, "there should be one pending request");
				Assert.AreEqual(1, MockTraceListener.ProcessedTraceRequests, "the request to the non blocking listener should have succedded");

				lock (MockBlockingCustomTraceListener.traceRequestMonitor)
				{
					Monitor.Pulse(MockBlockingCustomTraceListener.traceRequestMonitor);
				}
				for (int i = 0; i < 10; i++)
				{
					Thread.Sleep(10);
					if (MockBlockingCustomTraceListener.ProcessedTraceRequests == 1) break;
				}

				Assert.AreEqual(1, MockBlockingCustomTraceListener.ProcessedTraceRequests, "there should have been one written entries so far");
				Assert.AreEqual(0, MockBlockingCustomTraceListener.PendingTraceRequests, "there should be no pending request");
				Assert.AreEqual(1, MockTraceListener.ProcessedTraceRequests, "the request to the non blocking listener should have succedded");
			}
			finally
			{
				try { nonblockingLogThread.Join(50); }
				catch { }
				try { blockingLogThread.Join(50); }
				catch { }
			}
		}
		public void ConfigurationErrorsOnUpdateKeepExistingSetupAndLogError()
		{
			LogWriter logWriter = new LogWriterFactory(configurationSource).Create();
			Assert.IsNotNull(logWriter);

			{
				Assert.AreEqual(2, logWriter.TraceSources.Count);
				IEnumerator<LogSource> sources = logWriter.TraceSources.Values.GetEnumerator();
				sources.MoveNext();
				Assert.AreEqual("blocking", sources.Current.Name);
			}

			settings.TraceSources.Get(0).Name = "new source";
			settings.TraceSources.Get(0).TraceListeners.Get(0).Name = "invalid listener";

			using (EventLog eventLog = new EventLog("Application", ".", "Enterprise Library Logging"))
			{
				int previousEventCount = eventLog.Entries.Count;
				Thread notificationThread = new Thread(FireConfigurationSectionChangedNotification);
				notificationThread.Start();
				notificationThread.Join(1000);

				Assert.IsTrue(eventLog.Entries.Count > 0);
				EventLogEntry lastEntry = eventLog.Entries[eventLog.Entries.Count - 1];
				Assert.AreEqual("Enterprise Library Logging", lastEntry.Source);
			}

			{
				Assert.AreEqual(2, logWriter.TraceSources.Count);
				IEnumerator<LogSource> sources = logWriter.TraceSources.Values.GetEnumerator();
				sources.MoveNext();
				Assert.AreEqual("blocking", sources.Current.Name);
			}
		}
        public ActionResult LogViewerByModel(LogViewerModel model)
        {
            if (WebGrid<LogMessageModel, LogViewerModel, DataFilterLogger>.IsWebGridEvent())
            {
                this.ModelState.Clear();
                model.Filter = (DataFilterLogger)WebGrid<LogMessageModel, LogViewerModel, DataFilterLogger>.GetDataFilterFromPost();
                model.Filter.IsClientVisible = false;
            }

            model = this.LogViewerSetBreadcrumb(model, model.Filter.LogTraceSourceSelected, model.Filter.LogTraceListenerSelected);

            LogWriterFactory logWriterFactory = new LogWriterFactory();
            LogWriter logWriterInstance = logWriterFactory.Create();
            using (TraceListener traceListenerInstance = logWriterInstance.TraceSources[model.Filter.LogTraceSourceSelected]
                                                                          .Listeners.Where(p => p.Name == model.Filter.LogTraceListenerSelected).First())
            {
                if (traceListenerInstance is ICustomTraceListener)
                {
                    model.LogMessages = ((ICustomTraceListener)traceListenerInstance).SearchLogMessages(LogginConfigurationSectionName, model.Filter);
                    //model.Filter.NextContinuationToken = model.LogMessages.NextContinuationToken;
                    //model.Filter.PreviousContinuationToken = model.LogMessages.PreviousContinuationToken;
                    return View(LogViewerViewHelper.LogViewerDisplay, model);
                }
                else
                {
                    throw new Exception("TraceListener Not Supported");
                }
            }
        }
 public void Application_InitEnterpriseLibrary()
 {
     DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory());
     DependencyFactory.SetUnityContainerProviderFactory(UnityContainerProvider.GetContainer(FrontEndUnityContainerAvailable.ProxiesToAzure));
     LogWriterFactory logWriterFactory = new LogWriterFactory();
     Logger.SetLogWriter(logWriterFactory.Create());
 }
 private void EnterpriseLibrary_Init(IUnityContainer unityContainer)
 {
     DependencyFactory.SetUnityContainerProviderFactory(unityContainer);
     DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory());
     LogWriterFactory logWriterFactory = new LogWriterFactory();
     Logger.SetLogWriter(logWriterFactory.Create());
 }
        public void LogWriterCanGetConfiguredCategories()
        {
            LogSource source = null;

            LogWriter logWriter = new LogWriterFactory().Create();

            try
            {
                foreach (string key in logWriter.TraceSources.Keys)
                {
                    logWriter.TraceSources.TryGetValue(key, out source);
                    Assert.IsNotNull(source, key);
                    Assert.AreEqual(key, source.Name);
                }

                source = null;
                logWriter.TraceSources.TryGetValue("AppTest", out source);
            }
            finally
            {
                logWriter.Dispose();
            }

            Assert.IsNotNull(source);
        }