Chat Support
Loupe - Log - Monitor - Resolve
Loupe / Getting Started / .NET Framework / Using Loupe with ASP.NET MVC / Developer's Guide for ASP.NET - Submitting Sessions on Error
In This Topic
    Developer's Guide for ASP.NET - Submitting Sessions on Error
    In This Topic

    Sending the Current Session Automatically on Error

    A common request is to be able to submit the running session to the Server or send it via email whenever there is an error. The best way to do this is to use the Message Alert event. 

    When Auto Send Sessions is enabled on the server configuration this is done automatically by changing the default value of SendSession to true and the Minimum Delay to five minutes.  You can still subscribe to the MessageAlert event and override either of these settings.

    The simple way to connect is to register an event handler for this event in your Global.asax.cs file:

    Subscribing to the Message Alert event in the Global.asax.cs
    Copy Code
    using Gibraltar.Agent;
    
    public class Global : System.Web.HttpApplication
    {
        protected void Application_Start(object sender, EventArgs e)
        {
            Log.MessageAlert += Log_MessageAlert;
        }
        private void Log_MessageAlert(object sender, LogMessageAlertEventArgs e)
        {
            if (e.TopSeverity <= LogMessageSeverity.Error)
            {
                e.SendSession = true;
                e.MinimumDelay = new TimeSpan(0, 15, 0);
            }
        }
    }
    

    In the example MessageAlert handler above the session will be sent immediately when an error or critical message is logged and then there will be a fifteen minute delay before the event can be raised again to ensure data isn't pushed to the server too often, putting unnecessary pressure on the application.

    Sending the Current Session Manually

    Another common feature is to provide a means through the web site of submitting the running session immediately on demand, whether there has been an error or not.  To do this, create a button or some other user input option in an administration section of your web site and call the Packager class to send the data. 

    Simple Code to Package and Send Session Data
    Copy Code
    using Gibraltar.Agent;
    
    //Send all closed sessions that have never been sent before.
    using(Gibraltar.Agent.Packager newPackage = new Gibraltar.Agent.Packager())
    {
        //This is a synchronous send.  If you are doing this from a web server event you should use the Async equivalent method
        //But if you do it asynchronous do not immediately dispose the packager (like this using block does) or it will abort the send.
        newPackage.SendEmail(SessionCriteria.NewSessions, true, null, "support@yourcompany.com", "youremail@yourcompany.com");
    }
    
    //Send just the current running session (up to this point)
    using(Gibraltar.Agent.Packager newPackage = new Gibraltar.Agent.Packager())
    {
        //This is a synchronous send.  If you are doing this from a web server event you should use the Async equivalent method.
        //But if you do it asynchronous do not immediately dispose the packager (like this using block does) or it will abort the send.
         newPackage.SendEmail(SessionCriteria.ActiveSession, true, null, "support@yourcompany.com", "youremail@yourcompany.com");
    }
    

    You can also use the Packager to send data to the Server by using the SendToServer method.  This will make the data available to any Loupe Desktop that is subscribed to the Server.  If the active session is packaged multiple times each successive time will submit the entire session up to that point when packaging to a file or email.  Packaging to the server only sends data that hasn't already been uploaded to that server.

    See Also