
Using the Generic Host
The NServiceBus documentation section explains why you’d want to use the generic host here. I decided to use the generic host so that I could easily debug my handlers and services, just like they were running as a windows service. However I ran into a few issues with regards to Logging and Dependency Injection when working with different profiles.
NServiceBus comes with 3 default profiles out of the box:
- Lite - This uses an in memory subscription model and by default logs debug level messages to the console. (Very Busy)
- Integration - This uses MSMQ subscription model and by default logs info level messages to the console.
- Production - This uses a database subscription model and by default logs errors to a rolling file.
I wanted to control the level of logging depending on the profile that was running. Also I wanted to Inject different behaviour depending on the profile that was running. Here’s what I found out thanks to the excellent NServiceBus community:
How to change Logging for different NServiceBus profiles
I found the default logging that comes out of the box for the Lite profile to be much too busy, I decided I didn’t need to see DEBUG level logging and also wanted the profile to log to a Coloured Console rather than boring old white. Here are the steps to achieve this:
- Create a new class in your assembly somewhere, I called mine:
LoggingBehaviour.cs
- You have to inherit from the IConfigureLoggingForProfile interface as follows:
using log4net.Appender; using log4net.Appender; using log4net.Appender; using log4net.Core; using NServiceBus; namespace Company.Product { public class LiteLoggingBehavior : IConfigureLoggingForProfile<Lite> { public void Configure(IConfigureThisEndpoint specifier) { SetLoggingLibrary.Log4Net<ColoredConsoleAppender>(null, a => { a.AddMapping( new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.Green, Level = Level.Debug }); a.AddMapping( new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.Red | ColoredConsoleAppender.Colors.HighIntensity, Level = Level.Error }); a.AddMapping( new ColoredConsoleAppender.LevelColors { ForeColor = ColoredConsoleAppender.Colors.White, Level = Level.Info }); a.Threshold = Level.Info; }); } } }
- Lastly you have to update your app.config to include the section for NServiceBusLogging:
<section name="Logging" type="NServiceBus.Config.Logging, NServiceBus.Core" />
<Logging Threshold="INFO" />
- That’s it.. now when you get an error you’re console will light up nice and RED.. so you know what’s going on:

I think this makes it much clearer to detect issues when you’re coding.
How to change Behaviour using dependency injection for a profile
One of the services I was working on had an in memory repository for working locally and when live it used a SqlRepository. This again is very straightforward using the Generic host. Here are the steps to achieve this:
- Create a new class in your assembly somewhere, I called mine:
DependencyInjectionBehaviour.cs
- You have to inherit from the IHandleProfile interface as follows:
using NServiceBus; using NServiceBus.ObjectBuilder; namespace Company.Product { internal class LiteDependencyInjectionBehaviour: IHandleProfile<Lite> { public void ProfileActivated() { Configure.Instance.Configurer.ConfigureComponent<MemoryRepository>(ComponentCallModelEnum.Singleton); } } internal class ProductionDependencyInjectionBehaviour: IHandleProfile<Production>, IHandleProfile<Integration> { public void ProfileActivated() { Configure.Instance.Configurer.ConfigureComponent<SqlRepository>(ComponentCallModelEnum.Singleton); } } }
- That’s it.. now when running in Lite mode you won’t have to worry about configuring the connection to your database, etc.

As you can see from the above code, now when a reference IAmARepository as I’m running in Lite mode it’s using the MemoryRepository. To demo this I updated the default “FullDuplex” Example that comes with the NServiceBus download and I’ve saved it to my sky drive.
Thanks, helped me setting up coloured console appender :)
ReplyDeleteMachine Learning Projects for Final Year machine learning projects for final year
DeleteDeep Learning Projects assist final year students with improving your applied Deep Learning skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include Deep Learning projects for final year into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Deep Learning Projects for Final Year even arrange a more significant compensation.
Python Training in Chennai Python Training in Chennai Angular Training Project Centers in Chennai
No problem.. I think it now defaults to a coloured console. However it's useful to know how to inject different classes depending on the profile your're running the host as.
ReplyDeleteThanks for sharing. Appreciate it. Speaking about technologies these days. All of the paperwork is left behind and now it is time to go virtual. Read about data room providers and it will make sense to you.
ReplyDeleteObviously, a similar circumstance (icy atmosphere and the plenitude of building material) made them far reaching over lush locales.chicago electric chainsaw
ReplyDeleteDemikian tadi adalah cara untuk mendapatkan banyak sekali kemenangan dalam situs judi ceme. Hanya dengan menggunakan cara yang ada di atas, maka para penjudi akan mendapatkan banyak sekali keuntungan dalam permainan judi.
ReplyDeleteasikqq
http://dewaqqq.club/
http://sumoqq.today/
interqq
pionpoker
bandar ceme terpercaya
freebet tanpa deposit
paito warna
syair sgp
Nice Post.
ReplyDeleteEthical Hacking Training in chennai
Best Training Institute in Chennai
ReplyDeleteتعد الاول افضل شركة غسيل خزانات بالمدينة المنورة تعمل على استخدام افضل ادوات تنظيف وتعقيم خزانات المياه
GOOD ARTICLE
ReplyDeletefinal year project
mini projects for cse
final year projects for cse
final year projects for cse students
final year projects for cse domains
final year projects for cse in data mining
final year projects for cse with source code
final year project for ece
final year project in mechanical engineering
final year project for eee
Nice post!
ReplyDeleteWorried About QuickBooks Error ?Get in touch with QuickBooks expert for instant solution.
Click Here to know how to fix QuickBooks Error 248
Dial on QuickBooks Toll-free Number +1-855-977-7463.
"Our teaching method on IELTS, PTE, TOEFL General, Academic, Professional or Business English is quality teaching comparatively with widespread recognition."
ReplyDeletehttps://cambridgeacademyofenglish.com/#
Good post thanks for share information.
ReplyDeleteAppValley VIP APK
Cami Elliott
lola Iolani Momoa
rolling paper alternatives
Mp3boo
free edu email
This comment has been removed by the author.
ReplyDeleteKaliteli escort bayanlarla tanışma fırsatı yakalamak için tıkla: ankara escort - ankara escort - ankara escort - ankara escort - ankara escort - ankara escort - ankara escort - ankara escort - ankara escort
ReplyDeleteno deposit bonus forex 2021 - takipçi satın al - takipçi satın al - takipçi satın al - tiktok takipçi satın al - instagram beğeni satın al - instagram beğeni satın al - google haritalara yer ekleme - btcturk güvenilir mi - izlenme-satin-al.com - numarasmsonay.com - borsagazete.com - takipcisatinals.com - izlenme-satin-al.com/youtube - google haritalara yer ekleme - altyapısız internet - mikrofiber havlu - forexbonus2020.com - tiktok jeton hilesi - tiktok beğeni satın al - microsoft word ücretsiz indir - misli apk indir - binance güvenilir mi - takipçi satın al - mikrofiber havlu - uc satın al - takipçi satın al - takipçi satın al - finanspedia.com
ReplyDeletetakipçi satın al
ReplyDeletetakipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
takipçi satın al
instagram takipçi satın al
instagram takipçi satın al
ReplyDeleteucuz takipçi
takipçi satın al
https://takipcikenti.com
https://ucsatinal.org
instagram takipçi satın al
https://perdemodelleri.org
https://yazanadam.com
instagram takipçi satın al
balon perdeler
petek üstü perde
mutfak tül modelleri
kısa perde modelleri
fon perde modelleri
tül perde modelleri
https://atakanmedya.com
https://fatihmedya.com
https://smmpaketleri.com
https://takipcialdim.com
https://yazanadam.com
yasaklı sitelere giriş
aşk kitapları
yabancı şarkılar
sigorta sorgula
https://cozumlec.com
word indir ücretsiz
tiktok jeton hilesi
rastgele görüntülü sohbet
erkek spor ayakkabı
fitness moves
gym workouts
https://marsbahiscasino.org
http://4mcafee.com
http://paydayloansonlineare.com
marsbahis
ReplyDeletebetboo
sultanbet
marsbahis
betboo
sultanbet
Your post is helping me a lot. Its really nice and epic. Thanks a lot for the useful info on this topic. You did it so much well. I love to see more about GBWhatsApp. Keep sharing and updating. Also share more posts with us. Thank you.
ReplyDeleteyour article so amazing and informative. Your writing skill is also very well. Your article is really addictive. Keep posting. keep sharing the knowledge. I love to read your articles.
ReplyDeleteenglish stories english short stories with moral value What is the factorial of 100