Exemplo n.º 1
0
        static void Main(string[] args)
        {
            ILoggerManager loggerManager = new LoggerManager();

            Dictionary <string, object> settings = new Dictionary <string, object>();

            settings.Add("Log4Net.ConversionPattern", "%date [%thread] %-5level %logger - %message%newline");
            settings.Add("Log4Net.MaximumFileSize", "1MB");
            settings.Add("Log4Net.MaxSizeRollBackups", 5);
            settings.Add("Log4Net.File", @"d:\Log4NetLogger.txt");

            ILogger log4NetLogger = new Log4NetLogger("Log4NetLogger");

            log4NetLogger.Configure(settings);
            loggerManager.AddLogger("Log4NetLogger", log4NetLogger);

            ILogger eventLogLogger = new EventLogLogger("TestApp", "Application", 400, null);

            loggerManager.AddLogger("EventLogLogger", eventLogLogger);

            SystemLogger systemLogger = new SystemLogger(loggerManager);

            systemLogger.LogInfo("This is my first info log.");
            systemLogger.LogDebug("This is my first debug log.");
            systemLogger.LogWarning("This is my first warning log.");
            systemLogger.LogError(ErrorSeverity.Low, "This is my first low error log.", new Exception("This is my first low error log."));
            systemLogger.LogError(ErrorSeverity.Medium, "This is my first medium error log.", new Exception("This is my first medium error log."));
            systemLogger.LogError(ErrorSeverity.High, "This is my first high error log.", new Exception("This is my first high error log."));
            systemLogger.LogError(ErrorSeverity.Extreme, "This is my first extreme error log.", new Exception("This is my first extreme error log."));
            systemLogger.LogMethodStart("static void Main(string[] args)", new string[] { "args" }, new object[] { args });
            systemLogger.LogMethodEnd("static void Main(string[] args)", true);
            systemLogger.LogMethodEnd("static void Main(string[] args)", false);
        }
        public LoggingRegistry()
        {
            // Initial loging
            Log4NetLogger.Configure();

            For <ILogger>().Use <Log4NetLogger>();
        }
Exemplo n.º 3
0
        public void A_log4net_logger_is_configured()
        {
            var fileInfo = new FileInfo("Logging/log4net.xml");

            fileInfo.Exists.ShouldBeTrue("No log4net.xml found in test directory");

            Log4NetLogger.Configure(fileInfo);
        }
Exemplo n.º 4
0
        private void RegisterDependencies()
        {
            var    builder          = new ContainerBuilder();
            string connectionString = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;

            //// Register controllers
            //builder.RegisterControllers(typeof(Global).Assembly);
            // Register your MVC controllers. (MvcApplication is the name of
            // the class in Global.asax.)
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // OPTIONAL: Register web abstractions like HttpContextBase.
            builder.RegisterModule <AutofacWebTypesModule>();

            Log4NetLogger.Configure(connectionString);
            builder.Register(c => new LogManagerAdapter()).As <ILogManager>().InstancePerLifetimeScope();

            // HttpContext
            //builder.Register(c => new HttpContextWrapper(HttpContext.Current) as HttpContextBase).As<HttpContextBase>().InstancePerLifetimeScope();
            //builder.Register(c => c.Resolve<HttpContextBase>().Request).As<HttpRequestBase>().InstancePerLifetimeScope();
            //builder.Register(c => c.Resolve<HttpContextBase>().Response).As<HttpResponseBase>().InstancePerLifetimeScope();
            //builder.Register(c => c.Resolve<HttpContextBase>().Server).As<HttpServerUtilityBase>().InstancePerLifetimeScope();
            //builder.Register(c => c.Resolve<HttpContextBase>().Session).As<HttpSessionStateBase>().InstancePerLifetimeScope();

            // Services
            builder.RegisterType <OwinAuthenticationService>().As <IAuthenticationService>().InstancePerLifetimeScope();
            builder.RegisterType <UserService>().As <IUserService>().InstancePerLifetimeScope();
            //builder.RegisterType<ActiveDirectoryService>().As<IActiveDirectoryService>().InstancePerLifetimeScope();
            //builder.RegisterType<DateTimeAdapter>().As<IDateTime>().InstancePerLifetimeScope();
            //builder.RegisterType<DomainService>().As<IDomainService>().InstancePerLifetimeScope();
            //builder.RegisterType<EmailSender>().As<IEmailSender>().InstancePerLifetimeScope();
            //builder.RegisterType<EmailTemplateService>().As<IEmailTemplateService>().InstancePerLifetimeScope();
            //builder.RegisterType<LogService>().As<ILogService>().InstancePerLifetimeScope();
            //builder.RegisterType<MessageService>().As<IMessageService>().InstancePerLifetimeScope();
            //builder.RegisterType<MemoryCacheService>().As<ICacheService>().SingleInstance();
            //builder.RegisterType<RoleService>().As<IRoleService>().InstancePerLifetimeScope();
            //builder.RegisterType<SettingService>().As<ISettingService>().InstancePerLifetimeScope();
            //builder.RegisterType<TraceLogService>().As<ITraceLogService>().InstancePerLifetimeScope();


            //// Trace listener
            //builder.RegisterType<DatabaseTraceListener>().As<ITraceListener>()
            //    .WithParameter("connectionString", connectionString)
            //    .InstancePerLifetimeScope();

            //// Repository
            builder.RegisterType <ApplicationDbContext>().As <ApplicationDbContext>().InstancePerLifetimeScope();
            //builder.RegisterGeneric(typeof(EfRepository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope();
            //builder.Register<DbContext>(c => new AppDbContext(connectionString)).InstancePerLifetimeScope();

            //// Register Mvc filters
            //builder.RegisterFilterProvider();

            // Set the dependency resolver to be Autofac.
            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
        }
Exemplo n.º 5
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            Log4NetLogger.Configure();

            SetErrorFilter();
        }
Exemplo n.º 6
0
        public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request, System.ServiceModel.IClientChannel channel)
        {
            request = TransformMessage(request);

            MessageBuffer buffer = request.CreateBufferedCopy(int.MaxValue);
            Message       copy   = buffer.CreateMessage();

            var logger = Log4NetLogger.Configure();

            logger.Information(GetDocumentFromMessage(buffer.CreateMessage()).OuterXml);

            request = buffer.CreateMessage();

            return(null);
        }
Exemplo n.º 7
0
        public void AfterReceiveReply(ref System.ServiceModel.Channels.Message reply, object correlationState)
        {
            MessageBuffer buffer = reply.CreateBufferedCopy(int.MaxValue);
            Message       copy   = buffer.CreateMessage();

            var logger      = Log4NetLogger.Configure();
            var replyString = reply.ToString();

            logger.Information(replyString);
            ReportingService.LogUserActivity(replyString, LogTypes.BankLink);

            var doc = GetDocumentFromMessage(copy);

            if (!VerifySignature(doc))
            {
                throw new SignatureException("Signature is not valid");
            }

            reply = buffer.CreateMessage();
        }
Exemplo n.º 8
0
        protected void Application_Start()
        {
            // MiniProfilerEF6.Initialize();

            Logger = Log4NetLogger.Configure();
            Logger.Information("App is starting");

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);

            //RouteDebug.RouteDebugger.RewriteRoutesForTesting(RouteTable.Routes);

            DefaultModelBinder.ResourceClassKey = "ErrorMessages";

            ModelMetadataProviders.Current = new CustomModelMetadataProvider();

            MongoObjectIdGenerator.Register();
            MongoObjectIdSerializer.Register();
            BsonClassMap.RegisterConventions(new ConventionProfile().SetSerializationOptionsConvention(new LocalDateTimeSerializationConvention()), c => true);

            var kernel = new Ninject.Web.Common.Bootstrapper().Kernel;

            ServiceLocator.Resolver = kernel.GetService;

            BundleConfig.RegisterBundles(BundleTable.Bundles);

            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new LocalizedRazorViewEngine());
            ViewEngines.Engines.Add(new LocalizedWebFormViewEngine());

            //GlobalFilters.Filters.Add(new StackExchange.Profiling.Data..Profiling.MVCHelpers.ProfilingActionFilter());

            var chatService = ServiceLocator.Resolve <ChatService>();

            chatService.ClearClients();
        }
Exemplo n.º 9
0
 private void ConfigureLog4Net(ContainerBuilder builder, string connectionString)
 {
     Log4NetLogger.Configure(connectionString);
     builder.Register(c => new LogManagerAdapter()).As <ILogManager>().InstancePerLifetimeScope();
 }