예제 #1
0
 internal void CopyTo(EventContext other)
 {
     foreach (var kvp in _values)
     {
         other[kvp.Key] = kvp.Value;
     }
 }
예제 #2
0
파일: Program.cs 프로젝트: oylers/Spiffy
        static void Main()
        {
            // this should be the first line of your application
            Spiffy.Monitoring.NLog.Initialize(c => c
                .ArchiveEvery(FileArchivePeriod.Minute)
                .KeepMaxArchiveFiles(5)
                .MinLogLevel(Level.Info)
                .LogToPath(@"c:\logs\TestConsoleApp"));

            // key-value-pairs set here appear in every event message
            GlobalEventContext.Instance
                .Set("Application", "TestConsole");

            // info:
            using (var context = new EventContext())
            {
                context["Greeting"] = "Hello world!";
            }

            // warning:
            using (var context = new EventContext())
            {
                context.SetToWarning("cause something sorta bad happened");
            }

            // error:
            using (var context = new EventContext())
            {
                context.SetToError("cause something very bad happened");
            }

            var cutOffTime = DateTime.UtcNow.AddMinutes(5);

            while (DateTime.UtcNow < cutOffTime)
            {
                using (var context = new EventContext())
                {
                    context["MyCustomValue"] = "foo";

                    using (context.Time("LongRunning"))
                    {
                        DoSomethingLongRunning();
                    }

                    try
                    {
                        DoSomethingDangerous();
                    }
                    catch (Exception ex)
                    {
                        context.IncludeException(ex);
                    }
                }
            }
        }
예제 #3
0
 public void When_creating_event()
 {
     _context = new EventContext();
 }
예제 #4
0
 public void When_creating_event()
 {
     _context = new EventContext("MyComponent", "MyOperation");
 }