public Exporter Export()
        {
            // collect all the info
            _election = Db.Elections.SingleOrDefault(e => e.ElectionGuid == _electionGuid);

            var logger = new LogHelper(_electionGuid);
            logger.Add("Export to file started");

            if (_election == null) return null;

            var locations = Db.Locations.Where(l => l.ElectionGuid == _electionGuid);
            var computers = Db.Computers.Where(c => c.ElectionGuid == _electionGuid);

            var people = Db.People.Where(p => p.ElectionGuid == _electionGuid);
            var tellers = Db.Tellers.Where(t => t.ElectionGuid == _electionGuid);
            var results = Db.Results.Where(r => r.ElectionGuid == _electionGuid);
            var resultSummaries = Db.ResultSummaries.Where(r => r.ElectionGuid == _electionGuid);
            var resultTies = Db.ResultTies.Where(r => r.ElectionGuid == _electionGuid);
            var logs = Db.C_Log.Where(log => log.ElectionGuid == _electionGuid);

            var joinElectionUsers = Db.JoinElectionUsers.Where(j => j.ElectionGuid == _electionGuid);
            var users = Db.Users.Where(u => joinElectionUsers.Select(j => j.UserId).Contains(u.UserId));

            var ballots = Db.Ballots.Where(b => locations.Select(l => l.LocationGuid).Contains(b.LocationGuid));
            var votes = Db.Votes.Where(v => ballots.Select(b => b.BallotGuid).Contains(v.BallotGuid));

            var site = new SiteInfo();

            var blob = new
                {
                    Exported = DateTime.Now.ToString("o"),
                    ByUser = UserSession.MemberName,
                    UserEmail = UserSession.MemberEmail,
                    Server = site.ServerName,
                    Environment = site.CurrentEnvironment,
                    // elements
                    election = ExportElection(_election),
                    resultSummary = ExportResultSummaries(resultSummaries),
                    result = ExportResults(results),
                    resultTie = ExportResultTies(resultTies),
                    teller = ExportTellers(tellers),
                    user = ExportUsers(users),
                    location = ExportLocationComputerBallotVote(locations, computers, ballots, votes, logs),
                    person = ExportPeople(people),
                    reason = ExportReasons(),
                    //log = ExportLogs(logs)
                };

            var exportName = string.Format("{0} {1}.TallyJ",
                                           _election.DateOfElection.GetValueOrDefault(DateTime.Today)
                                                    .ToString("yyyy-MM-dd"),
                                           _election.Name);

            return new Exporter(blob, "TallyJ2", exportName);
        }
    private void ConfigureNLog()
    {
      // see http://nlog-project.org/wiki/Configuration_API
      var config = LogManager.Configuration;
      var target = config.FindTargetByName("logentries") as LeTarget;
      if (target != null)
      {
        var siteInfo = new SiteInfo();
        var newKey = "";
        if (siteInfo.CurrentEnvironment == "Dev")
        {
          try
          {
            newKey = File.ReadAllText(@"c:\AppHarborConfig.LogEntries.txt");
          }
          catch
          {
            // swallow this
          }
        }
        else
        {
          newKey = ConfigurationManager.AppSettings["LOGENTRIES_ACCOUNT_KEY"];
        }

        if (newKey.HasContent())
        {
          target.Key = newKey;
        }
      }
    }
    private void Application_Error(object sender, EventArgs e)
    {
      var mainException = Server.GetLastError().GetBaseException();

      var msgs = new List<string>();

      var logger = LogManager.GetCurrentClassLogger();
      var siteInfo = new SiteInfo();
      var mainMsg = mainException.GetAllMsgs("; ");
      
      msgs.Add(mainMsg);

      var ex = mainException;
      while (ex != null)
      {
        var dbEntityValidation = ex as DbEntityValidationException;
        if (dbEntityValidation != null)
        {
          var msg = dbEntityValidation.EntityValidationErrors
            .Select(eve => eve.ValidationErrors
                             .Select(ve => "{0}: {1}".FilledWith(ve.PropertyName, ve.ErrorMessage))
                             .JoinedAsString("; "))
            .JoinedAsString("; ");
          logger.Debug(msg);
          msgs.Add(msg);
        }

        ex = ex.InnerException;
      }

      logger.FatalException("Env: {0}  Err: {1}".FilledWith(siteInfo.CurrentEnvironment, msgs.JoinedAsString("; ")), mainException);

      var url = siteInfo.RootUrl;
      Response.Write(String.Format("Server Error: {0}", msgs.JoinedAsString("\r\n")));
      if (HttpContext.Current.Request.Url.AbsolutePath.EndsWith(url))
      {
        //Response.Write("Error on site");
      }else
      {
        //Response.Write(String.Format("<script>location.href='{0}'</script>", url));
        //Response.Write("Error on site");
      }
      Response.End();
    }