Skip to content

Instantly share code, notes, and snippets.

@ramonsmits
Last active December 23, 2015 10:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramonsmits/f590c83b92056dcdf3b6 to your computer and use it in GitHub Desktop.
Save ramonsmits/f590c83b92056dcdf3b6 to your computer and use it in GitHub Desktop.
NServiceBus Host EndpointConfiguration initializing Log4net xml configuration, app domain diagnostic events and using Profile to target NHibernate persistence
using System;
using NServiceBus;
using NServiceBus.Hosting.Profiles;
using NServiceBus.Log4Net;
using NServiceBus.Logging;
public class EndpointConfig : IConfigureThisEndpoint
{
public EndpointConfig()
{
log4net.Config.XmlConfigurator.Configure();
LogManager.Use<Log4NetFactory>();
var appDomainLogger = LogManager.GetLogger("AppDomain");
AppDomain.CurrentDomain.FirstChanceException += (o, ea) => { appDomainLogger.Debug("FirstChanceException", ea.Exception); };
AppDomain.CurrentDomain.UnhandledException += (o, ea) => { appDomainLogger.Debug("UnhandledException", ea.ExceptionObject as Exception); };
}
void IConfigureThisEndpoint.Customize(BusConfiguration busConfiguration)
{
busConfiguration.EndpointName("Samples.NServiceBus.Host");
busConfiguration.UseSerialization<JsonSerializer>();
busConfiguration.UsePersistence<InMemoryPersistence>();
}
}
namespace Test
{
public class ProductionHandler : IHandleProfile<Test.Production>
{
public void ProfileActivated(BusConfiguration busConfiguration)
{
log4net.LogManager.GetLogger(typeof(ProductionHandler)).Fatal("ProfileActivated");
busConfiguration.UsePersistence<NHibernatePersistence>();
busConfiguration.EnableInstallers();
}
}
public class Production : NServiceBus.Production
{
}
}
@shamglam
Copy link

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NServiceBus;
using NServiceBus.Log4Net;
using NServiceBus.Logging;

// ReSharper disable once CheckNamespace
namespace RISA
{
    public class RisaProductionHandler : NServiceBus.Hosting.Profiles.IHandleProfile<Production>
    {
        public void ProfileActivated(BusConfiguration config)
        {
            config.UsePersistence<NHibernatePersistence>();
        }
    }

    public class Production : NServiceBus.Production
    {
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment