public void SameLogWriterFactoryReturnsDifferentInstances()
        {
            LogWriterFactory factory = new LogWriterFactory();

            createdObject1 = factory.Create();
            createdObject2 = factory.Create();
            Assert.IsNotNull(createdObject1);
            Assert.IsFalse(object.ReferenceEquals(createdObject1, createdObject2));
        }
Example #2
0
        private static void ConfigureLogging()
        {
            IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
            var logWriterFactory = new LogWriterFactory(configurationSource);

            try
            {
                Logger.SetLogWriter(logWriterFactory.Create());
            }
            catch (InvalidOperationException)
            {
                Logger.Reset();
                Logger.SetLogWriter(logWriterFactory.Create());
            }
        }
        public void CustomListenerIsInvokedWhenConfigured()
        {
            const string ListenerName  = "Custom Listener";
            const string FormatterName = "Text Formatter";
            const string Template      = "My template";

            configurationStart.LogToCategoryNamed(CategoryName)
            .WithOptions
            .DoNotAutoFlushEntries()
            .SetAsDefaultCategory()
            .ToSourceLevels(SourceLevels.All)
            .SendTo
            .Custom(ListenerName, typeof(MyCustomTraceListener))
            .WithTraceOptions(TraceOptions.DateTime)
            .Filter(SourceLevels.Verbose)
            .FormatWith(new FormatterBuilder()
                        .TextFormatterNamed(FormatterName)
                        .UsingTemplate(Template));

            this.SetConfigurationSource();

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

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

            entry.Categories.Add(LoggingFixtureBase.CategoryName);

            this.writer.Write(entry);

            Assert.IsTrue(MyCustomTraceListener.Wrote);
        }
    static void InitializeLogger()
    {
        IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
        LogWriterFactory     logWriterFactory    = new LogWriterFactory(configurationSource);

        Logger.SetLogWriter(logWriterFactory.Create(), false);
    }
Example #5
0
        static void SimpleLogWriterWriteDecalarative()
        {
            // Create the default LogWriter object from the configuration.
            // The actual concrete type is determined by the configuration settings.
            Console.WriteLine("This example reads the configuration data from the config file.");
            LogWriterFactory logWriterFactory = new LogWriterFactory();
            var logWriter = logWriterFactory.Create();

            // Check if logging is enabled before creating log entries.
            if (logWriter.IsLoggingEnabled())
            {
                // The default values if not specified in call to Write method are:
                // - Category: "General"
                // - Priority: -1
                // - Event ID: 1
                // - Severity: Information
                // - Title: [none]
                logWriter.Write("Log entry created using the simplest overload (Declarative configuration).");
                Console.WriteLine("Created a Log Entry using the simplest overload.");
                logWriter.Write("Log entry with a single category. (Declarative configuration)", "General");
                Console.WriteLine("Created a Log Entry with a single category.");
                logWriter.Write("Log entry with a category, priority, and event ID. (Declarative configuration)", "General", 6, 9001);
                Console.WriteLine("Created a Log Entry with a category, priority, and event ID.");
                logWriter.Write("Log entry with a category, priority, event ID, and severity. (Declarative configuration)", "General", 5, 9002, TraceEventType.Warning);
                Console.WriteLine("Created a Log Entry with a category, priority, event ID, and severity.");
                logWriter.Write("Log entry with a category, priority, event ID, severity, and title. (Declarative configuration)", "General", 8, 9003, TraceEventType.Warning, "Logging Block Examples");
                Console.WriteLine("Created a Log Entry with a category, priority, event ID, severity, and title.");
                Console.WriteLine();
                Console.WriteLine("Open Windows Event Viewer 'Application' Log to see the results.");
            }
            else
            {
                Console.WriteLine("Logging is disabled in the configuration.");
            }
        }
Example #6
0
        /// <summary>
        /// Prepares the container.
        /// </summary>
        /// <returns></returns>
        public static IUnityContainer PrepareContainer()
        {
            var container = Singleton.GetInstance <IUnityContainer>(() => new UnityContainer());

            string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EntLib.config.xml");
            var    map  = new ExeConfigurationFileMap {
                ExeConfigFilename = path
            };
            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);

            try
            {
                var section = (UnityConfigurationSection)config.GetSection("unity");
                //section.Configure(container, "DefContainer");
                //For unity 3.0 version
                container.LoadConfiguration(section, "DefContainer");


                //For Entlib 6 :Exception Handling Application Block objects can no longer be created automatically from the Unity DI container.
                IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
                LogWriterFactory     logWriterFactory    = new LogWriterFactory(configurationSource);
                Microsoft.Practices.EnterpriseLibrary.Logging.Logger.SetLogWriter(logWriterFactory.Create());
                // Singleton
                ExceptionPolicyFactory exceptionPolicyFactory = new ExceptionPolicyFactory(configurationSource);
                ExceptionPolicy.SetExceptionManager(exceptionPolicyFactory.CreateManager());
            }
            catch (InvalidOperationException ioe)
            {
                Debug.WriteLine(ioe);
                // Microsoft.Practices.EnterpriseLibrary.Logging.Logger.Write(ioe, "ExceptionLogger");
                throw;
            }
            return(container);
        }
        public override void TestInitialize()
        {
            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(LoggingSettings.SectionName));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);
        }
        public LoggerService()
        {
            LogWriterFactory logWriterFactory = new LogWriterFactory();
            var logWriter = logWriterFactory.Create();

            Microsoft.Practices.EnterpriseLibrary.Logging.Logger.SetLogWriter(logWriter, false);
        }
Example #9
0
        public EntlibLog()
        {
            IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
            LogWriterFactory     logWriterFactory    = new LogWriterFactory(configurationSource);

            defaultWriter = logWriterFactory.Create();
        }
Example #10
0
        public void EntryIsLoggedWhenCategoryIsUnprocessed()
        {
            DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory(this.ConfigurationSource));

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

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

            LogEntry entry = new LogEntry();

            entry.Message = "Message 1";
            entry.Categories.Add("Most definitely UnprocessedCategory");
            entry.EventId  = 123;
            entry.Priority = 11;
            entry.Severity = TraceEventType.Error;
            entry.Title    = "Db Trace listener title1";

            this.writer.Write(entry);

            string result = GetLastLogMessage("Connection String");

            Assert.AreNotEqual(0, result.Length);
            Assert.AreEqual(entry.Message, result);
        }
Example #11
0
        private static void RunInReleaseMode()
        {
            IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();

            LogWriterFactory logWriterFactory = new LogWriterFactory(configurationSource);

            Microsoft.Practices.EnterpriseLibrary.Logging.Logger.SetLogWriter(logWriterFactory.Create());

            ExceptionPolicyFactory exceptionFactory = new ExceptionPolicyFactory(configurationSource);
            ExceptionManager       manager          = exceptionFactory.CreateManager();

            ExceptionPolicy.SetExceptionManager(manager);

            TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;
            Current.DispatcherUnhandledException       += CurrentOnDispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
            try
            {
                CloudDriveShellBootstrapper bootstrapper = new CloudDriveShellBootstrapper();
                bootstrapper.Run();
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
        }
Example #12
0
        [Ignore] // No Exception thrown
        public void ExceptionIsThrownWhenDbInstanceNameEmpty()
        {
            DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory(this.ConfigurationSource));
            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration10"));

            factory.Create();
        }
    /// <summary>
    /// Define the logging parameters
    /// </summary>
    public static void DefineLogger()
    {
        var    builder    = new ConfigurationSourceBuilder();
        string loggerPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

        builder.ConfigureLogging()
        .WithOptions
        .DoNotRevertImpersonation()
        .LogToCategoryNamed("LogWriter")
        .WithOptions.SetAsDefaultCategory()
        .SendTo.RollingFile("Rolling Flat File Trace Listener")
        .RollAfterSize(1000)
        .FormatWith(new FormatterBuilder()
                    .TextFormatterNamed("Text Formatter")
                    .UsingTemplate(@"Timestamp: {timestamp}{newline}Message: {message},{newline}Category: {category},{newline}Severity: {severity},{newline}Title:{title},{newline}ProcessId: {localProcessId},{newline}Process Name: {localProcessName},{newline}Thread Name: {threadName}"))
        .ToFile(loggerPath + Properties.Settings.Default.LogFileFolder);
        // Reference app.config
        using (DictionaryConfigurationSource configSource = new DictionaryConfigurationSource())
        {
            builder.UpdateConfigurationWithReplace(configSource);
            LogWriterFactory logWriterFactory = new LogWriterFactory(configSource);
            LogWriter        logWriter        = logWriterFactory.Create();
            Logger.SetLogWriter(new LogWriterFactory(configSource).Create());
        }
    }
        private void LoadConfig(string configSection)
        {
            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection(configSection));

            this.writer = factory.Create();
            Logger.SetLogWriter(this.writer);
        }
Example #15
0
        static EnterpriseLibraryLoggerAdapter()
        {
            IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
            LogWriterFactory     logWriterFactory    = new LogWriterFactory(configurationSource);

            Logger.Write(logWriterFactory.Create());
        }
        public void Initialize()
        {
            var factory = new LogWriterFactory();

            this.writer        = factory.Create();
            this.adapterHelper = new AdapterHelper();
        }
Example #17
0
        static void Main(string[] args)
        {
            var config  = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var section = config.GetSection(ConfigurationSourceSection.SectionName) as ConfigurationSourceSection;

            var dbConfigSourceElement = section.Sources.Get("DatabaseBlockSettings") as FileConfigurationSourceElement;
            var dbConfigSource        = new FileConfigurationSource(dbConfigSourceElement.FilePath);
            var dbFactory             = new DatabaseProviderFactory(dbConfigSource);

            DatabaseFactory.SetDatabaseProviderFactory(dbFactory);

            var logConfigSourceElement = section.Sources.Get("LoggingBlockSettings") as FileConfigurationSourceElement;
            var logConfigSource        = new FileConfigurationSource(logConfigSourceElement.FilePath);
            var logFactory             = new LogWriterFactory(logConfigSource);
            var logWriter = logFactory.Create();

            Logger.SetLogWriter(logWriter);
            logWriter.Write("123333");

            var exceptionConfigSourceElement = section.Sources.Get("ExceptionHandlingBlockSettings") as FileConfigurationSourceElement;
            var exceptionConfigSource        = new FileConfigurationSource(exceptionConfigSourceElement.FilePath);
            var exceptionFactory             = new ExceptionPolicyFactory(exceptionConfigSource);
            var exceptionManager             = exceptionFactory.CreateManager();

            ExceptionPolicy.SetExceptionManager(exceptionManager);

            ProcessException(exceptionManager, () => int.Parse("A"));

            Console.WriteLine("主函数执行完成,按任意键退出……");
            Console.ReadKey();
        }
Example #18
0
        public void MultipleFilesAreCreatedWhenUsingAsynchForRollingFlatFile()
        {
            string fileNameWithoutExtension = "AsynchTestingConfigForRollingFlatFile";
            string extension = ".log";
            string fileName  = fileNameWithoutExtension + extension;
            var    files     = Directory.GetFiles(".", "AsynchTestingConfigForRollingFlatFile.*");

            foreach (var file in files)
            {
                File.Delete(file);
            }

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

            using (var writer = factory.Create())
            {
                Parallel.Invoke(Enumerable.Range(0, 150).Select(i =>
                                                                new Action(() =>
                {
                    writer.Write("Test Asynch Message Config: " + i);
                })).ToArray());
            }

            Assert.IsTrue(File.Exists(fileName));
            Assert.IsTrue(File.Exists(fileNameWithoutExtension + "." + DateTime.Now.Year + ".1" + extension));
            Assert.IsTrue(File.Exists(fileNameWithoutExtension + "." + DateTime.Now.Year + ".6" + extension));
        }
Example #19
0
        public void EntryIsWrittenWhenLoggingUsingBinaryLogFormatter()
        {
            const string BinaryFileName = "trace.log";

            File.Delete(BinaryFileName);

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

            this.writer = factory.Create();

            LogEntry entry = LogEntryFactory.GetLogEntry();

            entry.Categories.Clear();
            entry.Categories.Add("General");

            if (writer.ShouldLog(entry))
            {
                this.writer.Write(entry);
            }

            Assert.IsTrue(File.Exists(BinaryFileName));

            FileInfo fileInfo = new FileInfo(BinaryFileName);

            Assert.IsTrue(fileInfo.Length > 0);

            LogEntry deserializedEntry = LogFileReader.GetEntry(BinaryFileName);

            Assert.AreEqual(entry.Message, deserializedEntry.Message);
            Assert.AreEqual(entry.Priority, deserializedEntry.Priority);
            Assert.AreEqual(entry.Severity, deserializedEntry.Severity);
        }
Example #20
0
        public void AllEntriesAreWrittenWhenUsingAsynchForFormattedDatabase()
        {
            this.ClearLogs();
            DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory(this.ConfigurationSource.GetSection), false);
            DatabaseProviderFactory factory = new DatabaseProviderFactory(this.ConfigurationSource.GetSection);

            Data.Database dbProvider = factory.CreateDefault();

            FormattedDatabaseTraceListener listener = new FormattedDatabaseTraceListener(dbProvider, "WriteLog", "AddCategory", new TextFormatter("TEST{newline}TEST"));
            string           unique   = Guid.NewGuid().ToString();
            LogWriterFactory factory1 = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration"));

            int messageContents = 0;

            using (var writer = factory1.Create())
            {
                Logger.SetLogWriter(writer);

                Parallel.Invoke(Enumerable.Range(0, 10000).Select(i =>
                                                                  new Action(() =>
                {
                    Logger.Write(unique + " Test Asynch Message: " + i);
                })).ToArray());
            }

            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                SqlCommand command = new SqlCommand("select COUNT(1) from Log where Message like '" + unique + " Test Asynch Message:%'", connection);
                messageContents = (Int32)command.ExecuteScalar();
                connection.Close();
            }

            Assert.AreEqual(10000, messageContents);
        }
Example #21
0
        public void EntryIsWrittenWhenWritingAnEntryPassingExtendedProperties()
        {
            string originalFile = "LoggerExtendedProperties.log";

            File.Delete(originalFile);

            this.ConfigureContainer(originalFile);
            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration101"));

            this.writer = factory.Create();

            string message = "Test message";

            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add("one", 1);
            properties.Add("two", 2);
            properties.Add("three", 3);

            this.writer.Write(message, properties);

            LogEntry deserializedEntry = LogFileReader.GetEntry(originalFile);

            Assert.AreEqual(message, deserializedEntry.Message);

            Assert.AreEqual(3, deserializedEntry.ExtendedProperties.Count);
        }
Example #22
0
        public void EntryIsWrittenWhenWritingAnEntryPassingExtPropsCategoryPriorityEventIdSeverityAndTitle()
        {
            string originalFile = "LoggerExtPropsCatPriorityEventIdSevTitle.log";

            this.ConfigureContainer(originalFile);
            LogWriterFactory factory = new LogWriterFactory((e) => this.ConfigurationSource.GetSection("loggingConfiguration101"));

            this.writer = factory.Create();

            string message = "Test message";

            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties.Add("one", 1);
            properties.Add("two", 2);
            properties.Add("three", 3);

            this.writer.Write(message, "General", 3, 5, TraceEventType.Information, "Sample Title", properties);

            LogEntry deserializedEntry = LogFileReader.GetEntry(originalFile);

            Assert.AreEqual(message, deserializedEntry.Message);
            Assert.AreEqual(3, deserializedEntry.Priority);
            Assert.AreEqual(TraceEventType.Information, deserializedEntry.Severity);
            Assert.AreEqual("Sample Title", deserializedEntry.Title);
            Assert.AreEqual(5, deserializedEntry.EventId);
            Assert.AreEqual(3, deserializedEntry.ExtendedProperties.Count);
        }
Example #23
0
        /// <summary>
        /// Log Event According logging application Block EL
        /// </summary>
        /// <param name="mensaje"></param>
        /// <param name="severidad"></param>
        /// <param name="loggingCategory"></param>
        /// <returns></returns>
        public static bool LogEvent(string mensaje, TraceEventType severidad, LoggingCategoryEnum loggingCategory)
        {
            try
            {
                IConfigurationSource configurationSource = ConfigurationSourceFactory.Create();
                LogWriterFactory     logWriterFactory    = new LogWriterFactory(configurationSource);
                Logger.SetLogWriter(logWriterFactory.Create(), false);

                Logger.Write(new LogEntry()
                {
                    Message    = mensaje,
                    Categories = new List <string>()
                    {
                        loggingCategory.ToString()
                    },
                    Severity = severidad,
                });


                return(true);
            }
            catch (Exception error)
            {
                return(false);
            }
        }
        public void LogIn(System.Diagnostics.TraceEventType traceEventType, string logMessage, int priority = 0, int eventId = 0, bool isAsync = false)
        {
            LogWriter defaultWriter;

            //            if (isAsync)
            //            {
            //                defaultWriter = new LogWriter(loggingConfigurationAsync);
            //            }
            //            else
            //            {
            //                defaultWriter = new LogWriter(loggingConfiguration);
            //            }

            // dla konfiguracji pobieranej z App.config
            defaultWriter = logWriterFactory.Create();

            if (!defaultWriter.IsLoggingEnabled())
            {
                return;
            }
            defaultWriter.Write(new LogEntry()
            {
                Severity  = traceEventType,
                TimeStamp = DateTime.Now,
                Message   = logMessage,
                Priority  = priority,
                EventId   = eventId
            });
        }
Example #25
0
        public void EntryIsLoggedWhenLoggingLevelIsChanged()
        {
            string fileName = "trace.log";

            File.Delete(fileName);

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

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

            var entry = LogEntryFactory.GetLogEntry();

            entry.Severity = System.Diagnostics.TraceEventType.Verbose;
            entry.Categories.Clear();
            entry.Categories.Add("General");

            this.writer.Write(entry);

            FileInfo info = new FileInfo(fileName);

            Assert.IsFalse(info.Exists);

            this.SetSourceLevel("General", SourceLevels.Critical);

            entry.Severity = TraceEventType.Critical;

            this.writer.Write(entry);

            info = new FileInfo(fileName);

            Assert.IsTrue(info.Exists);
            Assert.IsTrue(info.Length > 0);
        }
Example #26
0
        public void WhenCategoryFilterIsChanged()
        {
            string fileName = "trace.log";

            File.Delete(fileName);

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

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

            var entry = LogEntryFactory.GetLogEntry();

            entry.Severity = System.Diagnostics.TraceEventType.Critical;
            entry.Categories.Clear();
            entry.Categories.Add("General");

            this.writer.Write(entry);

            FileInfo info = new FileInfo(fileName);

            Assert.IsTrue(info.Exists);
            long originalLength = info.Length;

            this.ReplaceCategoryFilter("General");

            this.writer.Write(entry);

            info = new FileInfo(fileName);

            Assert.IsTrue(info.Length == originalLength);
        }
Example #27
0
        public void EntryIsWrittenWhenEventLogTraceListenerMin()
        {
            bool entrymade = false;

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

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

            var entry = LogEntryFactory.GetLogEntry();

            this.writer.Write(entry);

            EventLog events = new EventLog()
            {
                Log    = "Application",
                Source = "Enterprise Library Logging"
            };

            foreach (EventLogEntry elogentry in events.Entries)
            {
                if (elogentry.Message.Contains("Message: Sample Message."))
                {
                    entrymade = true;
                    break;
                }
            }

            if (entrymade == false)
            {
                Assert.Fail("Eventlog message not logged");
            }
        }
        public void EntryIsWrittenWhenLoggingWithXmlFile()
        {
            const string FilePath     = "sample.xml";
            const string ListenerName = "Xml File Listener";

            File.Delete(FilePath);

            configurationStart.LogToCategoryNamed(CategoryName)
            .WithOptions
            .SetAsDefaultCategory()
            .ToSourceLevels(SourceLevels.All)
            .SendTo
            .XmlFile(ListenerName)
            .ToFile(FilePath)
            .WithTraceOptions(TraceOptions.None);

            this.SetConfigurationSource();

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

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

            LogEntry entry = LogEntryFactory.GetLogEntry();

            entry.Categories.Add(CategoryName);

            writer.Write(entry);

            FileInfo info = new FileInfo(FilePath);

            Assert.IsTrue(info.Exists);
            Assert.IsTrue(info.Length > 0);
        }
Example #29
0
        public MelLogWriter(TraceEventType severity)
        {
            var logWriterFactory = new LogWriterFactory();

            Writer      = logWriterFactory.Create();
            LogSeverity = severity;
        }
Example #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AirLoggerAdapter"/> class.
        /// </summary>
        public AirLoggerAdapter()
        {
            var       factory = new LogWriterFactory();
            LogWriter writer  = factory.Create();

            Logger.SetLogWriter(writer);
        }
        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 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 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");
                }
            }
        }