static void Main(string[] args)
        {
            XmlConfigurator.Configure();

            appender = LogManager.GetRepository()
                       .GetAppenders()
                       .OfType <MemoryAppender>()
                       .Single();

            var now = DateTime.UtcNow;

            // Log message through LogBridge
            Time("LogBridge simple message: {0}", () => Log.Warning("Message"));

            // Log formatted message through LogBridge
            Time("LogBridge formatted message: {0}", () => Log.Warning("Message {0} {1} {2} {3}", 42, "87", now, 87.42));

            // Log message with location through LogBridge
            Time("LogBridge simple message with location: {0}", () => Log.Warning(LogLocation.Here(typeof(Program)), "Message"));

            // Log formatted message with location through LogBridge
            Time("LogBridge formatted message with location: {0}", () => Log.Warning(LogLocation.Here(typeof(Program)), "Message {0} {1} {2} {3}", 42, "87", now, 87.42));

            var logger = LogManager.GetLogger("RootLogger");

            // Log message directly through log4net
            Time("Log4Net simple message: {0}", () => logger.WarnFormat("Message"));

            // Log formatted message directly through log4net
            Time("Log4Net formatted message: {0}", () => logger.WarnFormat("Message {0} {1} {2} {3}", 42, "87", now, 87.42));

            Console.WriteLine("Press ENTER to exit.");
            Console.ReadLine();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var logWriterFactory = new LogWriterFactory();
            var logger           = logWriterFactory.Create();

            Log.Information("Application started.");

            var now = DateTime.UtcNow;

            // Log message through LogBridge
            Time("LogBridge simple message: {0}", () => Log.Warning("Message"));

            // Log formatted message through LogBridge
            Time("LogBridge formatted message: {0}", () => Log.Warning("Message {0} {1} {2} {3}", 42, "87", now, 87.42));

            // Log message with location through LogBridge
            Time("LogBridge simple message with location: {0}", () => Log.Warning(LogLocation.Here(typeof(Program)), "Message"));

            // Log formatted message with location through LogBridge
            Time("LogBridge formatted message with location: {0}", () => Log.Warning(LogLocation.Here(typeof(Program)), "Message {0} {1} {2} {3}", 42, "87", now, 87.42));

            var logData = new LogData(
                now,
                Guid.NewGuid(),
                Option.None <Guid>(),
                Level.Warning,
                "Message",
                "Username",
                "Machinename",
                42,
                "ProcessName",
                "AppDomainName",
                null,
                new LogLocation(),
                new Dictionary <string, object>());

            // Log formatted message directly through Enterprise Library
            Time("Enterprise Library formatted message: {0}",
                 () =>
            {
                var logEntry = new LogEntry()
                {
                    ActivityId         = logData.EventId,
                    AppDomainName      = logData.AppDomainName,
                    ExtendedProperties = logData.Properties,
                    Message            = logData.Message,
                    Severity           = TraceEventType.Warning,
                    TimeStamp          = logData.TimeStamp,
                    Title       = logData.Message.Substring(0, Math.Min(32, logData.Message.Length)),
                    MachineName = logData.MachineName,
                    ProcessId   = logData.ProcessIdString,
                    ProcessName = logData.ProcessName,
                    Priority    = 0
                };

                if (logger.ShouldLog(logEntry))
                {
                    logger.Write(logEntry);
                }
            });

            Console.WriteLine("Press ENTER to exit.");
            //Console.ReadLine();
        }