Example #1
0
        Usage()
        {
            #region Log4NetInCode

            PatternLayout layout = new PatternLayout
            {
                ConversionPattern = "%d [%t] %-5p %c [%x] - %m%n"
            };
            layout.ActivateOptions();
            ConsoleAppender consoleAppender = new ConsoleAppender
            {
                Threshold = Level.Debug,
                Layout    = layout
            };
            // Note that no ActivateOptions is required since NSB 4 does this internally
            // Note that no ActivateOptions is required since NSB 4 does this internally

            //Pass the appender to NServiceBus
            SetLoggingLibrary.Log4Net(null, consoleAppender);

            #endregion
        }
        public void Configure(IConfigureThisEndpoint specifier)
        {
            SetLoggingLibrary.Log4Net();

            var appender = new ColoredConsoleAppender
            {
                Layout    = new SimpleLayout(),
                Threshold = Level.Debug
            };

            appender.AddMapping(
                new ColoredConsoleAppender.LevelColors
            {
                Level     = Level.Debug,
                ForeColor = ColoredConsoleAppender.Colors.Purple
            });
            appender.AddMapping(
                new ColoredConsoleAppender.LevelColors
            {
                Level     = Level.Info,
                ForeColor = ColoredConsoleAppender.Colors.Green
            });
            appender.AddMapping(
                new ColoredConsoleAppender.LevelColors
            {
                Level     = Level.Warn,
                ForeColor = ColoredConsoleAppender.Colors.Yellow | ColoredConsoleAppender.Colors.HighIntensity
            });
            appender.AddMapping(
                new ColoredConsoleAppender.LevelColors
            {
                Level     = Level.Error,
                ForeColor = ColoredConsoleAppender.Colors.Red | ColoredConsoleAppender.Colors.HighIntensity
            });

            appender.ActivateOptions();

            log4net.Config.BasicConfigurator.Configure(appender);
        }
Example #3
0
        public Configure GetConfiguration(RunDescriptor runDescriptor, EndpointConfiguration endpointConfiguration, IConfigurationSource configSource)
        {
            var settings = runDescriptor.Settings;

            SetLoggingLibrary.Log4Net(null, new ContextAppender(runDescriptor.ScenarioContext, endpointConfiguration));


            var types = GetTypesToUse(endpointConfiguration);

            var transportToUse = settings.GetOrNull("Transport");

            Configure.Features.Enable <Features.Sagas>();

            SettingsHolder.SetDefault("ScaleOut.UseSingleBrokerQueue", true);

            var config = Configure.With(types)
                         .DefineEndpointName(endpointConfiguration.EndpointName)
                         .CustomConfigurationSource(configSource)
                         .DefineBuilder(settings.GetOrNull("Builder"))
                         .DefineSerializer(settings.GetOrNull("Serializer"))
                         .DefineTransport(settings)
                         .DefineSagaPersister(settings.GetOrNull("SagaPersister"));

            if (transportToUse == null ||
                transportToUse.Contains("Msmq") ||
                transportToUse.Contains("SqlServer") ||
                transportToUse.Contains("RabbitMq"))
            {
                config.UseInMemoryTimeoutPersister();
            }

            if (transportToUse == null || transportToUse.Contains("Msmq") || transportToUse.Contains("SqlServer"))
            {
                config.DefineSubscriptionStorage(settings.GetOrNull("SubscriptionStorage"));
            }

            return(config.UnicastBus());
        }
    public void Filtering()
    {
        #region Log4NetFiltering

        var appender = new ColoredConsoleAppender
        {
            Threshold = Level.Debug,
            Layout    = new SimpleLayout(),
        };

        appender.AddFilter(new LoggerMatchFilter
        {
            LoggerToMatch = "MyNamespace"
        });
        appender.AddFilter(new DenyAllFilter());
        appender.ActivateOptions();

        BasicConfigurator.Configure(appender);

        SetLoggingLibrary.Log4Net();

        #endregion
    }
        public void Init()
        {
            // Log the Bus
            SetLoggingLibrary.NLog();


            // License this instance
            NServiceBus.Configure.Instance
            .LicensePath(@"C:\NServiceBus\License\license.xml");

            logger.Info("--------MySaga Configure IBus-------");

            Configure.With()
            .DefaultBuilder()              // Autofac Default Container
            .UseTransport <Msmq>()         // MSMQ, will create Queues, Defualt
            .MsmqSubscriptionStorage()     // Create a subscription endpoint
            .InMemorySagaPersister()       //In memory implementation of ISagaPersister
            .UseInMemoryTimeoutPersister() //UseInMemoryTimeoutPersister, UseRavenTimeoutPersister
            .UnicastBus();                 // Create the default unicast Bus


            logger.Info("--------MySaga Saga Enabled--------");
        }
Example #6
0
        public void Init()
        {
            var mongoConnectionString = ConfigurationManager.AppSettings["MongoEventStoreConnectionString"];
            var mongoDatabase         = ConfigurationManager.AppSettings["MongoEventStoreDatabaseName"];

            //Move to config so that it can be changed
            //And Use a factory, this is DIRTY
            var container = new Container(expression =>
                                          expression.For <IContactQueryRepository>()
                                          .Use <Contact.Query.SqlServer.SqlContactQueryRepository>()
                                          //.Use<MongoContactQueryRepository>()
                                          //.Ctor<string>("connectionString")
                                          //.Is(mongoConnectionString)
                                          //.Ctor<string>("databaseName")
                                          //.Is(mongoDatabase)
                                          );

            SetLoggingLibrary.Log4Net(XmlConfigurator.Configure);
            Configure.With()
            .StructureMapBuilder(container)
            .EnablePerformanceCounters()
            .Log4Net();
        }
        public void Init()
        {
            SetLoggingLibrary.Log4Net(XmlConfigurator.Configure);

            ObjectFactory.Initialize(x => x.Scan(y =>
            {
                var assembliesToSkip = AssembliesToSkip().Select(Path.GetFileNameWithoutExtension);
                y.AssembliesFromApplicationBaseDirectory(assembly => !assembliesToSkip.Contains(assembly.GetName().Name));
                y.LookForRegistries();
            }));

            var config = Configure.With(AssembliesToScan())
                         .CustomConfigurationSource(new PluginConfigurationSource())
                         .StructureMapBuilder(ObjectFactory.Container)
                         .AdvancedXmlSerializer();

            if (Transport == Transport.UiPriority)
            {
                config = config.MsmqTransport <MsmqUiPriorityTransport>().IsTransactional(IsTransactional).IsolationLevel(IsolationLevel.ReadUncommitted)
                         .PurgeOnStartup(false);
            }
            else if (Transport == Transport.Routable)
            {
                config = config.MsmqTransport <MsmqRoutableTransport>().IsTransactional(IsTransactional).IsolationLevel(IsolationLevel.ReadUncommitted)
                         .HostingMode(RoutableTransportMode)
                         .PurgeOnStartup(false);
            }

            var bus = config.Sagas()
                      .TpDatabaseSagaPersister()
                      .TpUnicastBus()
                      //.ImpersonateSender(true)
                      .LoadMessageHandlers(GetHandlersOrder()).CreateBus();

            bus.Start();
        }
Example #8
0
    protected override void OnStart(string[] args)
    {
        #region logging
        PatternLayout layout = new PatternLayout
        {
            ConversionPattern = "%d %-5p %c - %m%n"
        };
        layout.ActivateOptions();
        ConsoleAppender appender = new ConsoleAppender
        {
            Layout    = layout,
            Threshold = Level.Info
        };
        appender.ActivateOptions();

        BasicConfigurator.Configure(appender);

        SetLoggingLibrary.Log4Net();
        #endregion

        #region create-config
        Configure configure = Configure.With();
        #endregion
        #region endpoint-name
        configure.DefineEndpointName("Samples.FirstEndpoint");
        #endregion

        #region container
        ContainerBuilder builder = new ContainerBuilder();
        //configure your custom services
        //builder.RegisterInstance(new MyService());
        IContainer container = builder.Build();
        configure.AutofacBuilder(container);
        #endregion

        #region serialization
        Configure.Serialization.Json();
        #endregion

        #region transport
        configure.UseTransport <Msmq>();
        #endregion

        #region sagas
        Configure.Features.Enable <Sagas>();
        #endregion

        #region persistence
        configure.InMemorySagaPersister();
        configure.UseInMemoryTimeoutPersister();
        configure.InMemorySubscriptionStorage();
        #endregion

        #region critical-errors
        Configure.Instance.DefineCriticalErrorAction((errorMessage, exception) =>
        {
            // Log the critical error
            logger.Fatal(string.Format("CRITICAL: {0}", errorMessage), exception);

            // Kill the process on a critical error
            Environment.FailFast(string.Format("The following critical error was encountered by NServiceBus:\n{0}\nNServiceBus is shutting down.", errorMessage), exception);
        });
        #endregion

        #region start-bus
        bus = configure.UnicastBus()
              .CreateBus()
              .Start(() => configure.ForInstallationOn <Windows>().Install());
        #endregion
    }
Example #9
0
 public void Configure(IConfigureThisEndpoint specifier)
 {
     // setup your logging infrastructure then call
     SetLoggingLibrary.Log4Net();
 }
Example #10
0
 public void Init()
 {
     Configure.Instance.RoutingSlips().Diagnostics();
     SetLoggingLibrary.Log4Net();
 }
    protected override void OnStart(string[] args)
    {
        #region logging
        PatternLayout layout = new PatternLayout
        {
            ConversionPattern = "%d %-5p %c - %m%n"
        };
        layout.ActivateOptions();
        ConsoleAppender appender = new ConsoleAppender
        {
            Layout    = layout,
            Threshold = Level.Info
        };
        appender.ActivateOptions();

        BasicConfigurator.Configure(appender);

        SetLoggingLibrary.Log4Net();
        #endregion

        #region create-config
        Configure configure = Configure.With();
        configure.DefineEndpointName("Samples.FirstEndpoint");
        #endregion

        #region container
        ContainerBuilder builder = new ContainerBuilder();
        //configure custom services
        //builder.RegisterInstance(new MyService());
        IContainer container = builder.Build();
        configure.AutofacBuilder(container);
        #endregion

        #region serialization
        configure.JsonSerializer();
        #endregion

        #region transport
        configure.MsmqTransport();
        #endregion

        #region sagas
        configure.Sagas();
        #endregion

        #region persistence
        configure.InMemorySagaPersister();
        configure.UseInMemoryTimeoutPersister();
        configure.InMemorySubscriptionStorage();
        #endregion

        #region critical-errors
        Configure.Instance.DefineCriticalErrorAction(() =>
        {
            //Write log entry in version 3 since this is not done by default.
            logger.Fatal("CRITICAL Error");

            // Kill the process on a critical error
            string output = "Critical error was encountered by NServiceBus:\nNServiceBus is shutting down.";
            Environment.FailFast(output);
        });
        #endregion

        #region start-bus
        bus = configure.UnicastBus()
              .CreateBus()
              .Start(() => configure.ForInstallationOn <Windows>().Install());
        #endregion

        bus.SendLocal(new MyMessage());
    }
Example #12
0
 public void Init()
 {
     // setup your logging infrastructure then call
     SetLoggingLibrary.Log4Net(null, new MyLogger());
 }
Example #13
0
        public void Init()
        {
            SetLoggingLibrary.Log4Net(log4net.Config.XmlConfigurator.Configure);

            Configure.With().Log4Net();
        }
 public void When_config_section_is_null_threshold_should_be_null()
 {
     Assert.IsNull(SetLoggingLibrary.GetThresholdFromConfigSection(null));
 }
Example #15
0
 public void Init()
 {
     // setup logging infrastructure
     SetLoggingLibrary.Log4Net(null, new MyLogger());
 }
        public void Configure(IConfigureThisEndpoint specifier)
        {
            SetLoggingLibrary.NLog();

            NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(new NLog.Targets.ColoredConsoleTarget());
        }