public void ListenerDataIsCreatedCorrectly()
        {
            RollingFlatFileTraceListenerData listenerData =
                new RollingFlatFileTraceListenerData(
                    "listener",
                    "log.txt",
                    "header",
                    "footer",
                    10,
                    "yyyy-MM-dd",
                    RollFileExistsBehavior.Increment,
                    RollInterval.Minute,
                    TraceOptions.DateTime,
                    "SimpleTextFormat");

            Assert.AreSame(typeof(RollingFlatFileTraceListener), listenerData.Type);
            Assert.AreSame(typeof(RollingFlatFileTraceListenerData), listenerData.ListenerDataType);
            Assert.AreEqual("listener", listenerData.Name);
            Assert.AreEqual("log.txt", listenerData.FileName);
            Assert.AreEqual(10, listenerData.RollSizeKB);
            Assert.AreEqual("yyyy-MM-dd", listenerData.TimeStampPattern);
            Assert.AreEqual(RollFileExistsBehavior.Increment, listenerData.RollFileExistsBehavior);
            Assert.AreEqual(RollInterval.Minute, listenerData.RollInterval);
            Assert.AreEqual(TraceOptions.DateTime, listenerData.TraceOutputOptions);
            Assert.AreEqual("SimpleTextFormat", listenerData.Formatter);
            Assert.AreEqual("header", listenerData.Header);
            Assert.AreEqual("footer", listenerData.Footer);
        }
            public SendToRollingFileTraceListenerBuilder(ILoggingConfigurationSendTo context, string listenerName)
                :base(context)
            {
                rollingTraceListenerData = new RollingFlatFileTraceListenerData()
                {
                    Name = listenerName
                };

                base.AddTraceListenerToSettingsAndCategory(rollingTraceListenerData);
            }
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds a <see cref="FlatFileTraceListener"/> based on an instance of <see cref="FlatFileTraceListenerData"/>.
        /// </summary>
        /// <seealso cref="TraceListenerCustomFactory"/>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="FlatFileTraceListenerData"/>.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of <see cref="FlatFileTraceListener"/>.</returns>
        public override TraceListener Assemble(IBuilderContext context, TraceListenerData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            RollingFlatFileTraceListenerData castObjectConfiguration
                = (RollingFlatFileTraceListenerData)objectConfiguration;

            ILogFormatter formatter = GetFormatter(context, castObjectConfiguration.Formatter, configurationSource, reflectionCache);

            RollingFlatFileTraceListener createdObject
                = new RollingFlatFileTraceListener(
                      castObjectConfiguration.FileName,
                      castObjectConfiguration.Header,
                      castObjectConfiguration.Footer,
                      formatter,
                      castObjectConfiguration.RollSizeKB,
                      castObjectConfiguration.TimeStampPattern,
                      castObjectConfiguration.RollFileExistsBehavior,
                      castObjectConfiguration.RollInterval
                      );

            return(createdObject);
        }
        public void CanCreatePoliciesForRollingFlatFileTraceListenerWithFormatter()
        {
            RollingFlatFileTraceListenerData listenerData
                = new RollingFlatFileTraceListenerData(
                    "listener",
                    Path.Combine(Environment.CurrentDirectory, "test.log"),
                    "header",
                    "footer",
                    100,
                    "pattern",
                    RollFileExistsBehavior.Overwrite,
                    RollInterval.Midnight,
                    TraceOptions.Callstack | TraceOptions.ProcessId,
                    "formatter");
            listenerData.Filter = SourceLevels.Error;
            loggingSettings.TraceListeners.Add(listenerData);

            FormatterData formatterData = new TextFormatterData("formatter", "template");
            loggingSettings.Formatters.Add(formatterData);

            using (var container = CreateContainer())
            {
                RollingFlatFileTraceListener createdObject =
                    (RollingFlatFileTraceListener)((ReconfigurableTraceListenerWrapper)container.Resolve<TraceListener>("listener")).InnerTraceListener;

                Assert.IsNotNull(createdObject);
                Assert.AreEqual("listener\u200cimplementation", createdObject.Name);
                Assert.AreEqual(listenerData.TraceOutputOptions, createdObject.TraceOutputOptions);
                Assert.IsNotNull(createdObject.Filter);
                Assert.IsInstanceOfType(createdObject.Filter, typeof(EventTypeFilter));
                Assert.AreEqual(listenerData.Filter, ((EventTypeFilter)createdObject.Filter).EventType);
                Assert.IsNotNull(createdObject.Formatter);
                Assert.AreSame(typeof(TextFormatter), createdObject.Formatter.GetType());
                Assert.AreEqual("template", ((TextFormatter)createdObject.Formatter).Template);
                Assert.AreEqual(listenerData.FileName, ((FileStream)((StreamWriter)createdObject.Writer).BaseStream).Name);
            }
        }
 public void WhenCreatingInstanceUsingDefaultContructor_ThenListenerDataTypeIsSet()
 {
     var listener = new RollingFlatFileTraceListenerData();
     Assert.AreEqual(typeof(RollingFlatFileTraceListenerData), listener.ListenerDataType);
 }
        public void CanDeserializeSerializedConfiguration()
        {
            string name = "some name";
            string fileName = "some filename";
            string timesTampPattern = "yyyy-MM-dd";
            int rollSizeKB = 10;
            RollFileExistsBehavior rollFileExistsBehavior = RollFileExistsBehavior.Increment;
            RollInterval rollInterval = RollInterval.Hour;
            TraceOptions traceOptions = TraceOptions.LogicalOperationStack;
            string SimpleTextFormat = "SimpleTextFormat";
            string header = "header";
            string footer = "footer";
            int maxArchivedFiles = 10;

            RollingFlatFileTraceListenerData data =
                new RollingFlatFileTraceListenerData(
                    name, fileName,
                    header,
                    footer,
                    rollSizeKB,
                    timesTampPattern,
                    rollFileExistsBehavior,
                    rollInterval,
                    traceOptions,
                    SimpleTextFormat,
                    SourceLevels.Critical);
            data.TraceOutputOptions = traceOptions;
            data.MaxArchivedFiles = maxArchivedFiles;

            LoggingSettings settings = new LoggingSettings();
            settings.TraceListeners.Add(data);

            IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>();
            sections[LoggingSettings.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            LoggingSettings roSettigs = (LoggingSettings)configurationSource.GetSection(LoggingSettings.SectionName);

            Assert.AreEqual(1, roSettigs.TraceListeners.Count);
            Assert.IsNotNull(roSettigs.TraceListeners.Get(name));
            Assert.AreEqual(TraceOptions.LogicalOperationStack, roSettigs.TraceListeners.Get(name).TraceOutputOptions);
            Assert.AreEqual(SourceLevels.Critical, roSettigs.TraceListeners.Get(name).Filter);
            Assert.AreSame(typeof(RollingFlatFileTraceListenerData), roSettigs.TraceListeners.Get(name).GetType());
            Assert.AreSame(typeof(RollingFlatFileTraceListenerData), roSettigs.TraceListeners.Get(name).ListenerDataType);
            Assert.AreSame(typeof(RollingFlatFileTraceListener), roSettigs.TraceListeners.Get(name).Type);
            Assert.AreEqual(fileName, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).FileName);
            Assert.AreEqual(timesTampPattern, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).TimeStampPattern);
            Assert.AreEqual(rollSizeKB, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).RollSizeKB);
            Assert.AreEqual(rollFileExistsBehavior, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).RollFileExistsBehavior);
            Assert.AreEqual(rollInterval, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).RollInterval);
            Assert.AreEqual("SimpleTextFormat", ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).Formatter);
            Assert.AreEqual(header, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).Header);
            Assert.AreEqual(footer, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).Footer);
            Assert.AreEqual(maxArchivedFiles, ((RollingFlatFileTraceListenerData)roSettigs.TraceListeners.Get(name)).MaxArchivedFiles);
        }
        public void CanCreateInstanceFromGivenConfiguration()
        {
            RollingFlatFileTraceListenerData listenerData = new RollingFlatFileTraceListenerData("listener", "log.txt", "header", "footer", 10, "yyyy-MM-dd", RollFileExistsBehavior.Increment,
                                                                                                 RollInterval.Minute, TraceOptions.DateTime, "SimpleTextFormat");

            MockLogObjectsHelper helper = new MockLogObjectsHelper();
            helper.loggingSettings.Formatters.Add(new TextFormatterData("SimpleTextFormat", "foobar template"));
            helper.loggingSettings.TraceListeners.Add(listenerData);

            TraceListener listener = GetListener("listener\u200cimplementation", helper.configurationSource);

            Assert.IsNotNull(listener);
            Assert.AreEqual("listener\u200cimplementation", listener.Name);
            Assert.AreEqual(listener.GetType(), typeof(RollingFlatFileTraceListener));
        }