Ejemplo n.º 1
0
 public HarvesterAppender()
 {
     Layout = new XmlLayoutSchemaLog4j();
     Binding = @"\\.\pipe\Harvester";
     BufferType = @"NamedPipeBuffer";
     MutexName = @"HarvesterMutex";
 }
Ejemplo n.º 2
0
        public void Setup()
        {
            var applicationDataDirectory =
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
                    "PCoMD", "Log");
            LogFilePath = Path.Combine(applicationDataDirectory, "PCoMD.xml");

            var hierarchy = (Hierarchy) LogManager.GetRepository();

            var patternLayout = new XmlLayoutSchemaLog4j();
            patternLayout.LocationInfo = true;
            patternLayout.ActivateOptions();

            var roller = new RollingFileAppender
            {
                AppendToFile = true,
                MaximumFileSize = "2MB",
                File = LogFilePath,
                PreserveLogFileNameExtension = true,
                MaxSizeRollBackups = 10,
                RollingStyle = RollingFileAppender.RollingMode.Size,
                Layout = patternLayout
            };
            roller.ActivateOptions();
            hierarchy.Root.AddAppender(roller);

            var memory = new MemoryAppender();
            memory.ActivateOptions();
            hierarchy.Root.AddAppender(memory);

            hierarchy.Root.Level = Level.Info;
            hierarchy.Configured = true;

            XmlConfigurator.Configure(hierarchy);
        }
Ejemplo n.º 3
0
        private long GetLog4NetTimestamp(DateTime dateTime)
        {
            var logXmlBuilder = new StringBuilder ();
            using (var writer = new StringWriter (logXmlBuilder))
            {
                var layout = new XmlLayoutSchemaLog4j ();
                var appender = new TextWriterAppender
                {
                    ImmediateFlush = true,
                    Layout = layout,
                    Writer = writer
                };
                var repository = LogManager.GetRepository (Assembly.GetCallingAssembly ());

                var eventData = new LoggingEventData
                {
                    LoggerName = "TestLogger",
                    TimeStamp = dateTime,
                    Level = log4net.Core.Level.Debug,
                    ThreadName = "TestThread",
                    Message = "Test message."
                };
                var @event = new LoggingEvent (typeof (TimestampTests), repository, eventData);
                appender.DoAppend (@event);

                writer.Flush ();

                appender.Close ();
            }

            var logXml = logXmlBuilder.ToString ();

            const string timestampStartMarker = "timestamp=\"";
            var timestampStart = logXml.IndexOf (timestampStartMarker) + timestampStartMarker.Length;
            Assume.That (timestampStart, Is.GreaterThanOrEqualTo (0));
            var timestampEnd = logXml.IndexOf ('"', timestampStart);
            Assume.That (timestampEnd, Is.GreaterThanOrEqualTo (0));

            var timestampString = logXml.Substring (timestampStart, timestampEnd - timestampStart);

            var timestamp = Int64.Parse (timestampString);

            return timestamp;
        }