Esempio n. 1
0
        public void FlatFileSinkDataTest()
        {
            string fileName = "testFlatFileName";
            string footer   = "testFooter";
            string header   = "testHeader";
            string name     = "testName";
            string type     = typeof(FlatFileSink).AssemblyQualifiedName;

            FlatFileSinkData data = new FlatFileSinkData();

            data.FileName = fileName;
            data.Footer   = footer;
            data.Header   = header;
            data.Name     = name;
            data.TypeName = type;

            FlatFileSinkNode node = new FlatFileSinkNode(data);

            GeneratedApplicationNode.Nodes.Add(node);
            FlatFileSinkData nodeData = (FlatFileSinkData)node.SinkData;

            Assert.AreEqual(fileName, nodeData.FileName);
            Assert.AreEqual(footer, nodeData.Footer);
            Assert.AreEqual(header, nodeData.Header);
            Assert.AreEqual(name, nodeData.Name);
            Assert.AreEqual(type, nodeData.TypeName);
        }
Esempio n. 2
0
        public void FlatFileSink()
        {
            string           sinkName = "SampleTextFileSink";
            FlatFileSinkData sink     = new FlatFileSinkData();

            sink.Name = sinkName;

            SinkFromFactory(sink);
        }
Esempio n. 3
0
        public void Setup()
        {
            FlatFileSinkData sinkParams = new FlatFileSinkData();

            sinkParams.FileName = CommonUtil.FileName;
            sinkParams.Header   = "";
            sinkParams.Footer   = "";
            this.sink           = new FlatFileSink();
            sink.Initialize(new TestLogSinkConfigurationView(sinkParams));
            CommonUtil.ResetEventLogCounter();
        }
Esempio n. 4
0
        public void FlatFileSinkDataPropertiesTest()
        {
            FlatFileSinkData data     = new FlatFileSinkData();
            string           fileName = "Filename";
            string           footer   = "Footer";
            string           header   = "Header";

            data.FileName = fileName;
            data.Footer   = footer;
            data.Header   = header;

            Assert.AreEqual(fileName, data.FileName);
            Assert.AreEqual(footer, data.Footer);
            Assert.AreEqual(header, data.Header);
        }
Esempio n. 5
0
        public void LogMessageToFlatFileWithNullFileName()
        {
            FlatFileSinkData sinkParams = new FlatFileSinkData();

            sinkParams.FileName = null;

            this.sink = new FlatFileSink();
            sink.Initialize(new TestLogSinkConfigurationView(sinkParams));

            CommonUtil.SendTestMessage(this.sink);

            Assert.AreEqual(1, CommonUtil.EventLogEntryCount(), "confirm warning written to event log");
            string entry    = CommonUtil.GetLastEventLogEntry();
            string expected = SR.DefaultLogDestinationMessage + Environment.NewLine + Environment.NewLine +
                              SR.FileSinkMissingConfiguration;

            Assert.IsTrue(entry.IndexOf(expected) > -1, "confirm error message");
        }
Esempio n. 6
0
        public void LogMessageToFlatFileWithNullHeaderFooter()
        {
            string           fileName   = "trace.log";
            FlatFileSinkData sinkParams = new FlatFileSinkData();

            sinkParams.FileName = fileName;
            sinkParams.Header   = null;
            sinkParams.Footer   = null;

            this.sink = new FlatFileSink();
            sink.Initialize(new TestLogSinkConfigurationView(sinkParams));

            CommonUtil.SendTestMessage(this.sink);

            FileStream   stream   = new FileStream(fileName, FileMode.Open, FileAccess.Read);
            StreamReader reader   = new StreamReader(stream);
            string       contents = reader.ReadToEnd();

            stream.Close();

            Assert.AreEqual(0, CommonUtil.EventLogEntryCount(), "confirm no messages written to event log");
            Assert.IsTrue(contents.IndexOf(CommonUtil.FormattedMessage) > -1, "confirm message is part of contents");
        }
Esempio n. 7
0
        private void WriteMessageToFile(LogEntry logEntry)
        {
            FlatFileSinkData flatFileSinkData = GetFlatFileSinkDataFromCursor();

            string directory = Path.GetDirectoryName(flatFileSinkData.FileName);

            if (directory.Length == 0)
            {
                directory = AppDomain.CurrentDomain.BaseDirectory;
            }
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }

            using (FileStream fileStream = new FileStream(Path.Combine(directory, flatFileSinkData.FileName),
                                                          FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
            {
                using (StreamWriter writer = new StreamWriter(fileStream))
                {
                    lock (syncObject)
                    {
                        if (flatFileSinkData.Header.Length > 0)
                        {
                            writer.WriteLine(flatFileSinkData.Header);
                        }
                        writer.WriteLine(FormatEntry(logEntry));
                        if (flatFileSinkData.Footer.Length > 0)
                        {
                            writer.WriteLine(flatFileSinkData.Footer);
                        }

                        writer.Flush();
                    }
                }
            }
        }
Esempio n. 8
0
        private bool ValidateParameters(LogEntry logEntry)
        {
            FlatFileSinkData flatFileSinkData = GetFlatFileSinkDataFromCursor();

            bool valid = true;

            if (flatFileSinkData.Header == null)
            {
                flatFileSinkData.Header = "";
            }
            if (flatFileSinkData.Footer == null)
            {
                flatFileSinkData.Footer = "";
            }

            if (flatFileSinkData.FileName == null || flatFileSinkData.FileName.Length == 0)
            {
                valid = false;
                logEntry.AddErrorMessage(SR.FileSinkMissingConfiguration);
                this.defaultSink.SendMessage(logEntry);
            }

            return(valid);
        }
Esempio n. 9
0
 /// <summary>
 /// Creates node with specified configuration data.
 /// </summary>
 /// <param name="flatFileSinkData">Configuration data.</param>
 public FlatFileSinkNode(FlatFileSinkData flatFileSinkData) : base(flatFileSinkData)
 {
     this.flatFileSinkData = flatFileSinkData;
 }
Esempio n. 10
0
        public void FlatFileSinkDataPropertiesTest()
        {
            FlatFileSinkData data = new FlatFileSinkData();
            string fileName = "Filename";
            string footer = "Footer";
            string header = "Header";

            data.FileName = fileName;
            data.Footer = footer;
            data.Header = header;

            Assert.AreEqual(fileName, data.FileName);
            Assert.AreEqual(footer, data.Footer);
            Assert.AreEqual(header, data.Header);
        }