public static Response LogError(NancyContext context, Exception exception) { ErrorSignal.FromCurrentContext().Raise(exception); return(null); }
public static ErrorSignal Get(HttpApplication application) { if (application == null) throw new ArgumentNullException("application"); lock (_lock) { // // Allocate map of object per application on demand. // if (_signalByApp == null) _signalByApp = new Dictionary<HttpApplication, ErrorSignal>(); // // Get the list of modules fot the application. If this is // the first registration for the supplied application object // then setup a new and empty list. // ErrorSignal signal = _signalByApp.Find(application); if (signal == null) { signal = new ErrorSignal(); _signalByApp.Add(application, signal); application.Disposed += new EventHandler(OnApplicationDisposed); } return signal; } }
/// <summary> /// Initializes the module and prepares it to handle requests. /// </summary> protected override void OnInit(HttpApplication application) { if (application == null) { throw new ArgumentNullException("application"); } // // Get the configuration section of this module. // If it's not there then there is nothing to initialize or do. // In this case, the module is as good as mute. // var config = (IDictionary)GetConfig(); if (config == null) { return; } // // Extract the settings. // var mailRecipient = GetSetting(config, "to"); var mailSender = GetSetting(config, "from", mailRecipient); var mailCopyRecipient = GetSetting(config, "cc", string.Empty); var mailSubjectFormat = GetSetting(config, "subject", string.Empty); var mailPriority = (MailPriority)Enum.Parse(typeof(MailPriority), GetSetting(config, "priority", MailPriority.Normal.ToString()), true); var reportAsynchronously = Convert.ToBoolean(GetSetting(config, "async", bool.TrueString)); var smtpServer = GetSetting(config, "smtpServer", string.Empty); var smtpPort = Convert.ToUInt16(GetSetting(config, "smtpPort", "0"), CultureInfo.InvariantCulture); var authUserName = GetSetting(config, "userName", string.Empty); var authPassword = GetSetting(config, "password", string.Empty); var sendYsod = Convert.ToBoolean(GetSetting(config, "noYsod", bool.FalseString)); var useSsl = Convert.ToBoolean(GetSetting(config, "useSsl", bool.FalseString)); // // Hook into the Error event of the application. // application.Error += OnError; ErrorSignal.Get(application).Raised += OnErrorSignaled; // // Finally, commit the state of the module if we got this far. // Anything beyond this point should not cause an exception. // _mailRecipient = mailRecipient; _mailSender = mailSender; _mailCopyRecipient = mailCopyRecipient; _mailSubjectFormat = mailSubjectFormat; _mailPriority = mailPriority; _reportAsynchronously = reportAsynchronously; _smtpServer = smtpServer; _smtpPort = smtpPort; _authUserName = authUserName; _authPassword = authPassword; _noYsod = sendYsod; _useSsl = useSsl; }