public ActionResult AddKeyboard( KeyboardModel keyboard ) { IActivityMonitor m = new ActivityMonitor(); KeyboardPostError err = KeyboardPostError.None; string uploadedFolderPath = AppSettings.Default.GetRequired<string>( "UploadFolderPath" ); using( m.OpenInfo().Send( "Try AddKeyboard" ) ) { if( ModelState.IsValid ) { if( Request.Files.Count > 0 ) { string filePath = Path.Combine( uploadedFolderPath, String.Format( "{0}-{1}", keyboard.Name, Guid.NewGuid() ) ); Request.Files[0].SaveAs( filePath ); using( m.OpenInfo().Send( "Sending Keyboard submitted mail to {0}", DestinationEmail ) ) { var model = new KeyboardSubmittedMailModel() { Name = keyboard.Name, Description = keyboard.Description, Email = keyboard.Email, Author = keyboard.Author }; try { IMailerService mailer = new CK.Mailer.DefaultMailerService( activityLogger: m ); mailer.SendMail( model, new RazorMailTemplateKey( "KeyboardSubmitted" ), new Recipient( DestinationEmail ) ); } catch( Exception ex ) { m.Error().Send( ex, "Email : {0}, Subject : {1}, Name : {2}, Description : {3}, Author : {4}", model.Email, model.Subject, model.Name, model.Description, model.Author ); } } } else { err = KeyboardPostError.MissingPicture; m.Error().Send( "Missing file." ); } } else { err = KeyboardPostError.InvalidForm; m.Error().Send( "InvalidForm" ); } return Json( new { valid = false, error = err, keyboard = keyboard } ); } }
public ActionResult Support( SupportEmailViewModel model ) { IActivityMonitor m = new ActivityMonitor(); if( ModelState.IsValid ) { using (m.OpenInfo().Send( "Sending Support mail to {0}", ConfigurationManager.AppSettings.Get( "DestinationEmail" ) )) { try { IMailerService mailer = new DefaultMailerService( m ); mailer.SendMail( model, new RazorMailTemplateKey( "SupportEmail" ), new Recipient( ConfigurationManager.AppSettings.Get( "DestinationEmail" ) ) ); } catch (Exception ex) { m.Error().Send( ex, "Email : {0}, Subject : {1}, Body : {2}", model.Email, model.Subject, model.Body ); return PartialView( "_EmailNotSent." + RouteData.Values["culture"], model ); } } return PartialView( "_EmailSent." + RouteData.Values["culture"] ); } return PartialView( "_Form." + RouteData.Values["culture"], model ); }
static void DumpSampleLogs2( Random r, GrandOutput g ) { var m = new ActivityMonitor( false ); g.Register( m ); m.Fatal().Send( ThrowExceptionWithInner( false ), "An error occured" ); m.SetTopic( "This is a topic..." ); m.Trace().Send( "a trace" ); m.Trace().Send( "another one" ); m.SetTopic( "Please, show this topic!" ); m.Trace().Send( "Anotther trace." ); using( m.OpenTrace().Send( "A group trace." ) ) { m.Trace().Send( "A trace in group." ); m.Info().Send( "An info..." ); using( m.OpenInfo().Send( @"A group information... with a multi -line message. This MUST be correctly indented!" ) ) { m.Info().Send( "Info in info group." ); m.Info().Send( "Another info in info group." ); m.Error().Send( ThrowExceptionWithInner( true ), "An error." ); m.Warn().Send( "A warning." ); m.Trace().Send( "Something must be said." ); m.CloseGroup( "Everything is in place." ); } } m.SetTopic( null ); using( m.OpenTrace().Send( "A group with multiple conclusions." ) ) { using( m.OpenTrace().Send( "A group with no conclusion." ) ) { m.Trace().Send( "Something must be said." ); } m.CloseGroup( new[] { new ActivityLogGroupConclusion( "My very first conclusion." ), new ActivityLogGroupConclusion( "My second conclusion." ), new ActivityLogGroupConclusion( @"My very last conclusion is a multi line one. and this is fine!" ) } ); } m.Trace().Send( "This is the final trace." ); }
static void DumpSampleLogs1( Random r, GrandOutput g ) { var m = new ActivityMonitor( false ); g.Register( m ); m.SetTopic( "First Activity..." ); if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); using( m.OpenTrace().Send( "Opening trace" ) ) { if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); m.Trace().Send( "A trace in group." ); if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); m.Info().Send( "An info in group." ); if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); m.Warn().Send( "A warning in group." ); if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); m.Error().Send( "An error in group." ); if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); m.Fatal().Send( "A fatal in group." ); } if( r.Next( 3 ) == 0 ) System.Threading.Thread.Sleep( 100 + r.Next( 2500 ) ); m.Trace().Send( "End of first activity." ); }
public void FilteringByTopic() { TestHelper.CleanupFolder( SystemActivityMonitor.RootLogPath + "FilteringByTopic" ); using( GrandOutput g = new GrandOutput() ) { GrandOutputConfiguration config = new GrandOutputConfiguration(); config.Load( XDocument.Parse( @" <GrandOutputConfiguration> <Channel MinimalFilter=""Debug""> <Add Type=""BinaryFile"" Name=""All"" Path=""FilteringByTopic"" /> <Channel Name=""HiddenTopic"" MinimalFilter=""Off"" TopicFilter=""*H*T?pic*"" > <Channel Name=""SavedHiddenTopic"" MinimalFilter=""Release"" TopicFilter=""*DOSHOW*"" > </Channel> </Channel> <Channel Name=""MonitoredTopic"" MinimalFilter=""Monitor"" TopicFilter=""*MONITOR*"" > </Channel> </Channel> </GrandOutputConfiguration>", LoadOptions.SetLineInfo ).Root, TestHelper.ConsoleMonitor ); Assert.That( g.SetConfiguration( config, TestHelper.ConsoleMonitor ) ); var fullyHidden = new ActivityMonitor( false ); g.Register( fullyHidden ); fullyHidden.SetTopic( "A fully hidden topic: setting the topic before any send, totally hides the monitor if the Actual filter is Off. - NOSHOW" ); fullyHidden.Fatal().Send( "NOSHOW" ); using( fullyHidden.OpenFatal().Send( "NOSHOW" ) ) { fullyHidden.Fatal().Send( "NOSHOW" ); } var m = new ActivityMonitor( false ); g.Register( m ); m.Trace().Send( "Trace-1" ); m.SetTopic( "This is a Hidden Topic - NOSHOW" ); m.Fatal().Send( "NOSHOW" ); m.SetTopic( "Visible Topic" ); m.Trace().Send( "Trace-2" ); m.SetTopic( "This is a Hidden Topic but DOSHOW puts it in Release mode." ); m.Trace().Send( "NOSHOW" ); m.Info().Send( "NOSHOW" ); m.Warn().Send( "NOSHOW" ); m.Error().Send( "Error-1" ); m.Fatal().Send( "Fatal-1" ); m.SetTopic( "This is a HT?PIC (off). Match is case insensitive - NOSHOW" ); m.Fatal().Send( "NOSHOW" ); m.SetTopic( null ); m.Trace().Send( "Trace-3" ); m.SetTopic( "A MONITORed topic: If i wrote This is a t.o.p.i.c (without the dots), this would have matched the HiddenT.o.p.i.c channel..." ); m.Trace().Send( "NOSHOW" ); m.Warn().Send( "Warn-1" ); } List<StupidStringClient> logs = TestHelper.ReadAllLogs( new DirectoryInfo( SystemActivityMonitor.RootLogPath + "FilteringByTopic" ), false ); Assert.That( logs.Count, Is.EqualTo( 1 ), "Fully hidden monitor does not appear." ); Assert.That( logs[0].ToString(), Does.Not.Contain( "NOSHOW" ) ); var texts = logs[0].Entries.Select( e => e.Text ).ToArray(); CollectionAssert.AreEqual( new string[] { "Trace-1", ActivityMonitor.SetTopicPrefix + "Visible Topic", "Trace-2", ActivityMonitor.SetTopicPrefix + "This is a Hidden Topic but DOSHOW puts it in Release mode.", "Error-1", "Fatal-1", ActivityMonitor.SetTopicPrefix, "Trace-3", ActivityMonitor.SetTopicPrefix + "A MONITORed topic: If i wrote This is a t.o.p.i.c (without the dots), this would have matched the HiddenT.o.p.i.c channel...", "Warn-1" }, texts, StringComparer.Ordinal ); }
public ActionResult Support( SupportEmailViewModel model ) { IActivityMonitor m = new ActivityMonitor(); if( ModelState.IsValid ) { using( m.OpenInfo().Send( "Sending Support mail to {0}", DestinationEmail ) ) { try { IMailerService mailer = new CK.Mailer.DefaultMailerService( m ); mailer.SendMail( model, new RazorMailTemplateKey( "SupportEmail" ), new Recipient( DestinationEmail ) ); } catch( Exception ex ) { m.Error().Send( ex, "Email : {0}, Subject : {1}, Body : {2}", model.Email, model.Subject, model.Body ); return PartialView( "_EmailNotSent", model ); } } return PartialView( "_EmailSent" ); } return PartialView( "_Form", model ); }