Beispiel #1
0
        private static void Main(string[] args)
        {
            var dir = Path.GetFullPath(args[0]);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }
            Console.WriteLine("Writing logs in {0}", dir);

            var config = string.Format(
                @"
<loggers>
  <etwlogging enabled='true' />
  <log name='demo' rotationInterval='60' type='etl' directory='{0}' timestampLocal='true'>
    <source name='Demo' minimumSeverity='informational' />
  </log>
</loggers>
", dir);

            LogManager.Start();
            LogAssert.Assert(LogManager.SetConfiguration(config));
            LogManager.ConsoleLogger.SubscribeToEvents(DemoEvents.Write, EventLevel.Verbose);
            LogManager.ConsoleLogger.SubscribeToEvents(InternalLogger.Write, EventLevel.Verbose);

            var t = new Timer(_ => DemoEvents.Write.Log(DateTime.Now.ToString()), null, TimeSpan.Zero,
                              new TimeSpan(0, 0, 1));

            Console.CancelKeyPress +=
                (sender, eventArgs) =>
            {
                Console.WriteLine("Shutting down...");
                LogManager.Shutdown();
                Environment.Exit(0);
            };

            while (true)
            {
                Thread.Sleep(100);
            }
        }