Ejemplo n.º 1
0
 public SqlLogger(SqlLoggingRepository repo)
 {
     _repo = repo;
 }
Ejemplo n.º 2
0
        //Our composition Root
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            var emailConfig = ConfigurationManager.GetSection("EmailLogger") as EmailLogConfiguration; //Ensure Web.Config is correctly configured.
            if (emailConfig == null)
                throw new ConfigurationErrorsException("Email Logger was not configured correctly");
            ILogger emailLoggingProvider = new EmailLogger(emailConfig);

            SqlLoggingRepository sqlLogRepo = new SqlLoggingRepository();
            ILogger sqlLoggingProvider = new SqlLogger(sqlLogRepo);

            Global.Logger = new LoggingService(sqlLoggingProvider, emailLoggingProvider);

            string userName = ConfigurationManager.AppSettings["AdminDefaultUserName"];
            if (Membership.FindUsersByName(userName).Count == 0)
            {
                string password = ConfigurationManager.AppSettings["AdminDefaultPassword"];
                string email = ConfigurationManager.AppSettings["AdminDefaultEmail"];

                MembershipCreateStatus createStatus;
                Membership.CreateUser(userName, password, email, passwordQuestion: null, passwordAnswer: null, isApproved: true, providerUserKey: null, status: out createStatus);
                if (createStatus != MembershipCreateStatus.Success)
                    throw new MembershipCreateUserException(createStatus.ToString());
            }

            var unhandledErrorAttr = new LoggingHandleErrorAttribute(Global.Logger);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters, new object[] { unhandledErrorAttr });

            Database.SetInitializer<PersonalWebsiteContext>(new ContextInitializer());

            _cache = new CachingProvider();
            var controllerFactory = new PersonalWebsiteControllerFactory(_cache);
            ControllerBuilder.Current.SetControllerFactory(controllerFactory);
        }
 public ErrorController(SqlLoggingRepository repo)
 {
     _repo = repo;
 }