We have an NServiceBus service configured to run sagas. With InMemory-persistence everything runs fine. When trying to change the profile to NServiceBus.Integration, we get an error when starting the service.
Endpoint configuration:
public class MyEndpoint : IConfigureThisEndpoint, AsA_Server, IWantCustomInitialization
{
private IContainer _container;
public void Init()
{
log4net.Config.XmlConfigurator.Configure();
SetupStructureMap();
Configure.With()
.Log4Net()
.StructureMapBuilder(_container)
.Sagas()
.XmlSerializer();
}
private void SetupStructureMap()
{
[...]
}
}
Error message:
FATAL 2012-01-18 11:11:52,197 2640ms GenericHost Start - FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
* Database was not configured through Database method.
---> System.ArgumentException: The number of generic arguments provided doesn't equal the arity of the generic type definition.
Parameter name: instantiation
at System.RuntimeType.MakeGenericType(Type[] instantiation)
at FluentNHibernate.Automapping.AutoMapManyToMany.GetInverseProperty(PropertyInfo property)
at FluentNHibernate.Automapping.AutoMapManyToMany.MapsProperty(PropertyInfo property)
at FluentNHibernate.Automapping.AutoMapper.TryToMapProperty(ClassMappingBase mapping, PropertyInfo property, IList`1 mappedProperties)
at FluentNHibernate.Automapping.AutoMapper.MapEverythingInClass(ClassMappingBase mapping, Type entityType, IList`1 mappedProperties)
at FluentNHibernate.Automapping.AutoMapper.MergeMap(Type classType, ClassMappingBase mapping, IList`1 mappedProperties)
at FluentNHibernate.Automapping.AutoMapper.Map(Type classType, List`1 types)
at FluentNHibernate.Automapping.AutoPersistenceModel.AddMapping(Type type)
at FluentNHibernate.Automapping.AutoPersistenceModel.CompileMappings()
at FluentNHibernate.Cfg.AutoMappingsContainer.Apply(Configuration cfg)
at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg)
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
--- End of inner exception stack trace ---
at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration()
at NServiceBus.SagaPersisters.NHibernate.Config.Internal.SessionFactoryBuilder.UpdateDatabaseSchemaUsing(FluentConfiguration fluentConfiguration)
at NServiceBus.SagaPersisters.NHibernate.Config.Internal.SessionFactoryBuilder.Build(IDictionary`2 nhibernateProperties, Boolean updateSchema)
at NServiceBus.ConfigureNHibernateSagaPersister.NHibernateSagaPersister(Configure config, IDictionary`2 nhibernateProperties, Boolean autoUpdateSchema)
at NServiceBus.ConfigureNHibernateSagaPersister.NHibernateSagaPersisterWithSQLiteAndAutomaticSchemaGeneration(Configure config)
at NServiceBus.Host.Internal.ProfileHandlers.IntegrationProfileHandler.NServiceBus.IHandleProfile.ProfileActivated()
at NServiceBus.Host.Internal.ProfileManager.<ActivateProfileHandlers>b__14(IHandleProfile hp)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at NServiceBus.Host.Internal.ProfileManager.ActivateProfileHandlers()
at NServiceBus.Host.Internal.GenericHost.Start()
* Database was not configured through Database method.
Configuration file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="MsmqTransportConfig" type="NServiceBus.Config.MsmqTransportConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" requirePermission="false" />
<section name="MsmqSubscriptionStorageConfig" type="NServiceBus.Config.MsmqSubscriptionStorageConfig,NServiceBus.Core" />
</configSections>
<MsmqTransportConfig InputQueue="MyQueue" ErrorQueue="MyQueueError" NumberOfWorkerThreads="1" MaxRetries="5" />
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="My.MessageContracts" Endpoint="MyQueue" />
</MessageEndpointMappings>
</UnicastBusConfig>
<log4net debug="false">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="C:\Log\My.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="RollingLogFileAppender" />
</root>
</log4net>
</configuration>
Looks like you are missing the following from the config, it is in the app.config of the OrderService in the samples:
<section name="DBSubscriptionStorageConfig" type="NServiceBus.Config.DBSubscriptionStorageConfig, NServiceBus.Core" />
<section name="NHibernateSagaPersisterConfig" type="NServiceBus.Config.NHibernateSagaPersisterConfig, NServiceBus.Core" />
<DBSubscriptionStorageConfig>
<NHibernateProperties>
<add Key="connection.provider" Value="NHibernate.Connection.DriverConnectionProvider"/>
<add Key="connection.driver_class" Value="NHibernate.Driver.SQLite20Driver"/>
<add Key="connection.connection_string" Value="Data Source=.\Subscriptions.sqlite;Version=3;New=True;"/>
<add Key="dialect" Value="NHibernate.Dialect.SQLiteDialect"/>
</NHibernateProperties>
</DBSubscriptionStorageConfig>
<NHibernateSagaPersisterConfig>
<NHibernateProperties>
<add Key="connection.provider" Value="NHibernate.Connection.DriverConnectionProvider"/>
<add Key="connection.driver_class" Value="NHibernate.Driver.SqlClientDriver"/>
<add Key="connection.connection_string" Value="Server=localhost;initial catalog=NServiceBus;Integrated Security=SSPI"/>
<add Key="dialect" Value="NHibernate.Dialect.MsSql2000Dialect"/>
</NHibernateProperties>
</NHibernateSagaPersisterConfig>
The problem was, as Andreas touched upon, on persisting the SagaData-class using NHibernate/Fluent NHibernate.
Just to summarize all the things that were wrong:
In order to use the profile NServicebus.Integration, you need to add a reference to SQLite (use NuGet)
In order to use the profile NServiceBus.Production, you need to set up connection to the database in app.config, as Adam showed in his answer.
In order to use both these two profiles, your SagaData-class must be playing by the rules of NHibernate:
All properties must be virtual
The class must not be sealed
The same goes for the type of all properties
All this is for NServiceBus 2.6. In 3.0, which is in Beta6 now, they use RavenDB instead, with no binding to NHibernate or SQLite. How the transition from 2.6 to 3.0 is, I do not know yet, but I think this is the way we are going on this project.
Related
The configuration section 'log4net' cannot be read because it is missing a section declaration
We have two web projects and one is referenced from another.
how do I publish both and setup application pools?
Currently I only publish the main webproject as it has the second(toolbox-wps) as a dependency
My project in IIS:
When I try to right-click and Browse wps it gives me the above error
My config file on server under wps folder is:
<configuration>
<configSections>
<section name="aws" type="Amazon.AWSSection, AWSSDK" />
<!-- For more information on Entity Framework configuration, visit
http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</configSections>
<aws profileName="development" />
<!--<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework,
Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,
log4net" />
</configSections>-->
...
<log4net debug="true">
<appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="Logs\ToolboxWPSWebAPILog.txt" />
<appendToFile value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n" />
</layout>
</appender>
<root>
<level value="INFO" />
Change this for production to WARN OR INFO
<appender-ref ref="RollingLogFileAppender" />
Using this appender - rolling file
</root>
but it does not get updated on publish.
This file is clearly missing
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler,
log4net" />
The question is how can I add it? Manually changing the config does not work it gives following error.
HTTP Error 502.5 - ANCM Out-Of-Process Startup Failure
Also, in my vs code, there is no web config file under wps(Toolbox-WPS) project.
I have tried adding a web config under wps(Toolbox-WPS) project and add the above line there and then publish but no updates on the server!
Locally everything works fine, Also this is .net core migration from nf4.6.1, the nf4.6.1 version in production also works fine!!
The web config file under wps folder doesnot get updated on publish.
The application pool for both is
I have an Azure cloud service which uses Quartz.Net (2.3.2) to run scheduled tasks. My main logging engine is Log4Net (2.0.3) , and I am using Common.Logging.Log4Net1213 (3.0.0) to bridge Common.Logging and Log4Net. I am using my own "NinjectJobFactory" to create all the jobs and their dependencies (It implements IJobFactory). My schedule startup code looks like this:
_scheduler = factory.GetScheduler();
_scheduler.JobFactory = new NinjectJobFactory(_kernel);
_scheduler.Start();
Everything works perfectly for normal, everyday logging (Quartz startup and shutdown, NServiceBus startup, tasks starting, exception handling inside jobs, etc). The problem I have is when there is a fatal exception in any of the lines above which prevents Quartz from starting. (Usually, this is because I have failed to properly include or configure a dependency that one of the jobs needs). Under these circumstances, instead of logging the real problem, I get an exception inside Log4NetLogger.cs complaining about an unknown logging level, and the underlying exception is never surfaced or logged. I have to break on caught exceptions in order to see the underlying exception. Can anyone suggest a fix? Thanks in advance!
The stack trace looks like this:
Microsoft.WindowsAzure.ServiceRuntime Critical: 1 : Unhandled
Exception: System.ArgumentOutOfRangeException: unknown log level
Parameter name: logLevel Actual value was Error. at
Common.Logging.Log4Net.Log4NetLogger.GetLevel(LogLevel logLevel) in
c:_oss\common-logging\src\Common.Logging.Log4Net129\Logging\Log4Net\Log4NetLogger.cs:line
180 at Common.Logging.Log4Net.Log4NetLogger.WriteInternal(LogLevel
logLevel, Object message, Exception exception) in
c:_oss\common-logging\src\Common.Logging.Log4Net129\Logging\Log4Net\Log4NetLogger.cs:line
140 at Common.Logging.Factory.AbstractLogger.Error(Object message,
Exception exception) in
c:_oss\common-logging\src\Common.Logging.Portable\Logging\Factory\AbstractLogger.cs:line
806 at Quartz.Simpl.SimpleThreadPool.WorkerThread.Run() in
c:\Program Files
(x86)\Jenkins\workspace\Quartz.NET\src\Quartz\Simpl\SimpleThreadPool.cs:line
492 at
System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx) at
System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx) at
System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state) at
System.Threading.ThreadHelper.ThreadStart()
My common.logging config in the app.config is:
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1213">
<arg key="configType" value="FILE" />
<arg key="configFile" value="log4net.config" />
</factoryAdapter>
</logging>
</common>
Finally, my log4net.config is:
<log4net>
<appender name="ErrorAppender" type="log4net.Appender.BufferingForwardingAppender">
<bufferSize value="1" />
<lossy value="true" />
<evaluator type="log4net.Core.LevelEvaluator">
<threshold value="INFO" />
</evaluator>
<appender-ref ref="TraceAppender" />
</appender>
<appender name="TraceAppender" type="log4net.Appender.TraceAppender">
<threshold value="INFO" />
<filter type="log4net.Filter.LoggerMatchFilter">
<loggerToMatch value="NServiceBus.Azure.Transports.WindowsAzureServiceBus.AzureServiceBusQueueCreator" />
<acceptOnMatch value="false" />
</filter>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message%newline" />
</layout>
</appender>
<root>
<level value="ALL" />
<appender-ref ref="ErrorAppender" />
</root>
</log4net>
This may sound silly, but I was facing the exact same problem and I overcame it by making sure the versions of common.logging, common.logging.core, and common.logging.log4net1213 were all of the same version (3.3.1). Apparently, there is version dependency between the three libraries, and if one is used with another not the same version, this can result.
Here is the decompiled code for the function from which your exception is originating. It comes from Common.Logging.Log4Net1213 v3.3.1. Previous versions of this code didn't exactly account for Common.Logging.LogLevel.Warn, and so the exception fell out at the bottom of the switch statement:
public static Level GetLevel(Common.Logging.LogLevel logLevel)
{
switch (logLevel)
{
case Common.Logging.LogLevel.All:
return Level.All;
case Common.Logging.LogLevel.Trace:
return Level.Trace;
case Common.Logging.LogLevel.Debug:
return Level.Debug;
case Common.Logging.LogLevel.Info:
return Level.Info;
case Common.Logging.LogLevel.Warn:
return Level.Warn;
case Common.Logging.LogLevel.Error:
return Level.Error;
case Common.Logging.LogLevel.Fatal:
return Level.Fatal;
default:
throw new ArgumentOutOfRangeException("logLevel", (object) logLevel, "unknown log level");
}
}
In my case, common.logging.log4net1213 was one version behind the others (v3.3.0), so I updated the library to the same version as the other two libraries, and the problem evaporated.
Good luck!
Can you show us your log config?
My Servicebus/log4net/quartz implementation logs quartz startup issues successfully. This is the startup code i use; not sure if it will help as not seen your code.
NSB Version 4.6.2
public class MyServer : ServiceControl
{
private readonly ILog logger;
private ISchedulerFactory schedulerFactory;
private IScheduler scheduler;
public static IBus Bus = null;
public MyServer()
{
logger = LogManager.GetLogger(GetType());
}
public virtual void Initialize()
{
try
{
log4net.GlobalContext.Properties["Job"] = "Quartz";
Configure.Serialization.Xml();
Configure.Transactions.Enable();
SetLoggingLibrary.Log4Net();
Bus = Configure.With().DefaultBuilder().UnicastBus().SendOnly();
schedulerFactory = CreateSchedulerFactory();
scheduler = GetScheduler();
}
catch (Exception e)
{
logger.Error("Server initialization failed:" + e.Message, e);
throw;
}
}
}
public class Configuration
{
private static readonly NameValueCollection configuration;
static Configuration()
{
configuration = (NameValueCollection)ConfigurationManager.GetSection("quartz");
}
static public string GetQuartzConfigFileName()
{
return configuration["quartz.plugin.xml.fileNames"] as String;
}
}
And my app config looks like this
<configuration>
<configSections>
<section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4net1211">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<log4net debug="false">
<appender name="ColoredConsoleAppender" type="log4net.Appender.ColoredConsoleAppender">
<mapping>
<level value="FATAL" />
<foreColor value="Red, HighIntensity" />
</mapping>
<mapping>
<level value="ERROR" />
<foreColor value="Red, HighIntensity" />
</mapping>
<mapping>
<level value="WARN" />
<foreColor value="Yellow" />
</mapping>
<mapping>
<level value="INFO" />
<foreColor value="Green" />
</mapping>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="GrafOI.Scheduler.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="10000KB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<!-- quartz clutters the logs so turn it off unless an error occurs -->
<logger name="Quartz">
<level value="ERROR" />
</logger>
<root>
<level value="DEBUG" />
<appender-ref ref="AdoNetAppender" />
<appender-ref ref="EventLogAppender" />
<appender-ref ref="ColoredConsoleAppender" />
<appender-ref ref="RollingFileAppender" />
</root>
</log4net>
<quartz>
<add key="quartz.scheduler.instanceName" value="GrafOI Scheduler" />
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<add key="quartz.threadPool.threadCount" value="2" />
<add key="quartz.threadPool.threadPriority" value="Normal" />
<add key="quartz.jobStore.misfireThreshold" value="60000" />
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.StdAdoDelegate, Quartz" />
<add key="quartz.jobStore.tablePrefix" value="QRTZ_" />
<add key="quartz.jobStore.dataSource" value="myDS" />
<add key="quartz.dataSource.myDS.connectionString" value="server=.;database=GrafOI;Integrated Security=true;" />
<add key="quartz.dataSource.myDS.provider" value="SqlServer-20" />
<add key="quartz.plugin.xml.type" value="Quartz.Plugin.Xml.XMLSchedulingDataProcessorPlugin, Quartz" />
<add key="quartz.plugin.xml.fileNames" value="~/GrafOI.Scheduler.Jobs.xml" />
<add key="quartz.jobStore.useProperties" value="true" />
</quartz>
<appSettings>
</appSettings>
</configuration>
Maybe there is something in there that helps
When I run a unit test, this is the error I'm getting:
SetUp : Spring.Objects.Factory.ObjectDefinitionStoreException : Error registering object with name 'NHibernateSessionFactory' defined in 'assembly [Eiq.Middleware.Data.DomainRepository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c61376b85e43767], resource [Eiq.Middleware.Data.DomainRepository.Persistence.xml] line 15' : Could not resolve placeholder 'TDM.providerName'.
at Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer.ProcessProperties(IConfigurableListableObjectFactory factory, NameValueCollection props)
at Spring.Objects.Factory.Config.PropertyResourceConfigurer.PostProcessObjectFactory(IConfigurableListableObjectFactory factory)
at Spring.Context.Support.AbstractApplicationContext.InvokeObjectFactoryPostProcessors(IList objectFactoryPostProcessors, IConfigurableListableObjectFactory objectFactory)
at Spring.Context.Support.AbstractApplicationContext.InvokeObjectFactoryPostProcessors(IConfigurableListableObjectFactory objectFactory)
at Spring.Context.Support.AbstractApplicationContext.Refresh()
at Spring.Context.Support.XmlApplicationContext..ctor(XmlApplicationContextArgs args)
at Spring.Context.Support.XmlApplicationContext..ctor(String[] configurationLocations)
at Spring.Testing.NUnit.AbstractSpringContextTests.LoadContextLocations(String[] locations)
at Spring.Testing.NUnit.AbstractDependencyInjectionSpringContextTests.LoadContextLocations(String[] locations)
at Spring.Testing.NUnit.AbstractSpringContextTests.GetContext(Object key)
at Spring.Testing.NUnit.AbstractDependencyInjectionSpringContextTests.SetUp()
Is there any way I could get it to somehow pass in the value for "TDM.providerName" by setting something in my unit test app.config? This is what I have tried, but it did not help, where the name of the test project is MiddlewareTests, and the default namespace is Eiq.Middleware.SmokeTest:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="databaseProperties" type="System.Configuration.NameValueSectionHandler, System" />
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" restartOnExternalChanges="true" />
</sectionGroup>
</configSections>
<appSettings>
<add key="DefaultUserName" value="tdmuser" />
<!-- Well Query Limit -->
<add key="WellQueryLimit" value="50000" />
<add key="TDM.providerName" value="SqlServer-2.0"/>
</appSettings>
<spring>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
<parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" />
<parser type="Spring.Aop.Config.AopNamespaceParser, Spring.Aop" />
</parsers>
<context>
<resource uri="assembly://MiddlewareTests/Eiq.Middleware.SmokeTest/Persistence.xml" />
<resource uri="assembly://MiddlewareTests/TEiq.Middleware.SmokeTest/Repositories.xml" />
<resource uri="assembly://MiddlewareTests/Eiq.Middleware.SmokeTest/Services.xml" />
<resource uri="config://spring/objects" />
</context>
<objects configSource="config\spring.config" />
</spring>
</configuration>
Or, alternatively, how could I get the application to point to copies of Persistence.xml, Repositories.xml, and Services.xml files that I have modified for testing directly in my unit testing project? Does anyone have any other suggestions?
To resolve the above issue, performed several steps, though I'm not sure specifically which one fixed it:
Added reference to NHibernate.Validator, Version=1.3.1.4000 in my test project and NHibernate.Caches.SysCache, Version 3.1.0.4000
Added reference log4net, Version=1.2.10.0 to my test project to print out more diagnostic info
Added references to System.Configuration, System.Web.ApplicationServices, and System.Web.Extensions to my test project
Removed references to Spring.Core and Spring.Data from my test project.
Also, updated the App.config file in my test project to the following, with they key parts being those related to hibernate-configuration:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="databaseProperties" type="System.Configuration.NameValueSectionHandler, System" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
<section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
<section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" restartOnExternalChanges="true" />
</sectionGroup>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
<section name="nhv-configuration" type="NHibernate.Validator.Cfg.ConfigurationSectionHandler, NHibernate.Validator" requirePermission="false" />
<section name="auditConfig" type="Eiq.Middleware.Common.Config.AuditConfigSectionHandler, Eiq.Middleware.Common" restartOnExternalChanges="true" />
<section name="coordSys" type="Eiq.Middleware.Common.Config.CoordSysSectionHandler, Eiq.Middleware.Common" restartOnExternalChanges="true" />
</configSections>
<log4net>
<appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%message%newline" />
</layout>
</appender>
<root>
<level value="INFO" />
<appender-ref ref="ConsoleAppender" />
</root>
</log4net>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">Data Source=localhost;Initial Catalog=ENERGYIQ;User Id=svc_tdm;Password=svc_tdm;
</property>
<mapping assembly="TdmTests" />
</session-factory>
<nhv-configuration xmlns="urn:nhv-configuration-1.0">
<shared_engine_provider class="NHibernate.Validator.Event.NHibernateSharedEngineProvider, NHibernate.Validator" />
</nhv-configuration>
<auditConfig configSource="Config\audit.config" />
<connectionStrings configSource="config\connectionStrings.config" />
<spring>
<parsers>
<parser type="Spring.Data.Config.DatabaseNamespaceParser, Spring.Data" />
<parser type="Spring.Transaction.Config.TxNamespaceParser, Spring.Data" />
<parser type="Spring.Aop.Config.AopNamespaceParser, Spring.Aop" />
</parsers>
<context>
<resource uri="assembly://TdmTests/TdmTests/Persistence.xml" />
<resource uri="assembly://TdmTests/TdmTests/Repositories.xml" />
<resource uri="assembly://TdmTests/TdmTests/Services.xml" />
<resource uri="config://spring/objects" />
</context>
<objects configSource="config\spring.config" />
</spring>
<appSettings>
<add key="DefaultUserName" value="tdmuser" />
<!-- Well Query Limit -->
<add key="WellQueryLimit" value="50000" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
HTH.
I'm attempting to use NServiceBus with RabbitMQ in a self-hosted scenario. I've obtained the source for the NServiceBus and NServiceBus.RabbitMQ repos on github to track down the issues I've had so far, so the version I'm using is the source on their repos as of yesterday.
Here is my configuration:
var busConfiguration = new BusConfiguration();
busConfiguration.EndpointName("RMAQueue");
busConfiguration.AssembliesToScan(typeof(RMACommand).Assembly);
busConfiguration.Conventions()
.DefiningCommandsAs(type => type.Namespace != null && type.Namespace.StartsWith("RMAInterfaces.Commands.", StringComparison.Ordinal));
busConfiguration.Conventions()
.DefiningEventsAs(type => type.Namespace != null && type.Namespace.StartsWith("RMAInterfaces.Events.", StringComparison.Ordinal));
busConfiguration.Conventions()
.DefiningMessagesAs(type => type.Namespace != null && type.Namespace.StartsWith("RMAInterfaces.Messages.", StringComparison.Ordinal));
busConfiguration.UseTransport<RabbitMQTransport>();
busConfiguration.Transactions().Disable();
busConfiguration.PurgeOnStartup(true);
busConfiguration.UseSerialization<NServiceBus.JsonSerializer>();
busConfiguration.DisableFeature<SecondLevelRetries>();
busConfiguration.DisableFeature<StorageDrivenPublishing>();
busConfiguration.DisableFeature<TimeoutManager>();
busConfiguration.UsePersistence<InMemoryPersistence>();
busConfiguration.EnableInstallers();
var bus = Bus.Create(busConfiguration);
I am getting an exception on the Bus.Create() line:
{"The given key (NServiceBus.LocalAddress) was not present in the dictionary."}
Following the stack from it leads me to see that it's failing while enabling the Feature UnicastBus.
Here is my app config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="AuditConfig" type="NServiceBus.Config.AuditConfig, NServiceBus.Core" />
</configSections>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />
<UnicastBusConfig>
<MessageEndpointMappings>
<add Messages="RMAInterfaces" Endpoint="RMAQueue#localhost" />
</MessageEndpointMappings>
</UnicastBusConfig>
<connectionStrings>
<add name="NServiceBus/Transport" connectionString="host=localhost" />
<add name="NServiceBus/Persistence" connectionString="host=localhost"/>
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<!--<AuditConfig
QueueName="The address to which messages received will be forwarded."
OverrideTimeToBeReceived="The time to be received set on forwarded messages, specified as a timespan see http://msdn.microsoft.com/en-us/library/vstudio/se73z7b9.aspx" />-->
<AuditConfig QueueName="audit" />
</configuration>
What am I missing to be able to self-host NServiceBus using a RabbitMQ transport?
I have just had this exact problem, and the fix is as Andreas suggested. I added the following to my configuration code...
configuration.AssembliesToScan(typeof(NServiceBus.Transports.RabbitMQ.IManageRabbitMqConnections).Assembly);
With that in place the error message regarding NServiceBus.LocalAddress no longer shows up. My complete setup is as follows (code, then config file)
[TestMethod]
public void TestMethod1()
{
LogManager.Use<Log4NetFactory>();
var configuration = new BusConfiguration();
configuration.AssembliesToScan(typeof(NServiceBus.Transports.RabbitMQ.IManageRabbitMqConnections).Assembly);
configuration.UseSerialization<JsonSerializer>();
configuration.UseTransport<NServiceBus.RabbitMQTransport>();
configuration.UsePersistence<InMemoryPersistence>();
var bus = global::NServiceBus.Bus.Create(configuration);
bus.Start();
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, Log4net" />
</configSections>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />
<connectionStrings>
<add name="NServiceBus/Transport" connectionString="host=localhost" />
</connectionStrings>
<UnicastBusConfig>
<MessageEndpointMappings>
<add Assembly="TestNSBCreation" Endpoint="TestNSBCreation" />
</MessageEndpointMappings>
</UnicastBusConfig>
<log4net>
<root>
<level value="DEBUG" />
<appender-ref ref="LogFileAppender" />
<appender-ref ref="ContactAppender" />
</root>
<appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="C:\logs\TestNSBCreation.log" />
<param name="AppendToFile" value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="10MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<param name="ConversionPattern" value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
</log4net>
</configuration>
The Morgan Skinner's answer helped figure out the actual root cause of my issue. I've added the suggested code configuration.AssembliesToScan(typeof(NServiceBus.Transports.RabbitMQ.IManageRabbitMqConnections).Assembly);
After that the exception was more descriptive. NServiceBus.RabbitMQ package automatically downloads RabbitMQ.Client package. The later package was updated to the latest available on nuget and this created version conflict between what expected by NserviceBus.RabbitMQ and what was actually installed. I've removed both packages completely and reinstalled NserviceBus.RabbitMQ package and the error went away. The ..assembliesToScan... line was no longer needed either.
I am attempting to overhaul one application's (a console app written in VB.NET) logging system using log4net.
I configured log4net according to this CodeProject tutorial. After configuring, I have discovered that the following log initialization creates empty logs (the resulting folder structure is correct and it creates the correct, dated text file, but the file is empty):
Private ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(Reflection.MethodBase.GetCurrentMethod().DeclaringType)
However, if I use the following line, it logs correctly.
Private ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger("VSED")
In my main module, I'm logging an error like so:
log.Error("Test error!")
And I'm loading the assembly like so:
<Assembly: log4net.Config.XmlConfigurator(Watch:=True)>
Below is my app.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net"/>
</configSections>
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
<file value="logs\" />
<datePattern value="dd.MM.yyyy'.log'" />
<appendToFile value="true" />
<rollingStyle value="Composite" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="100KB" />
<staticLogFileName value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] – %message%newline" />
</layout>
</appender>
<logger name="VSED">
<level value="DEBUG"/>
<appender-ref ref="RollingFileAppender"/>
</logger>
<filter type="log4net.Filter.LevelRangeFilter">
<levelMin value="INFO"/>
<levelMax value="FATAL"/>
</filter>
</log4net>
<system.diagnostics>
<sources>
<!-- This section defines the logging configuration for My.Application.Log -->
<source name="DefaultSource" switchName="DefaultSwitch">
<listeners>
<add name="FileLog"/>
<!-- Uncomment the below section to write to the Application Event Log -->
<!--<add name="EventLog"/>-->
</listeners>
</source>
</sources>
<switches>
<add name="DefaultSwitch" value="Information" />
</switches>
<sharedListeners>
<add name="FileLog"
type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"
initializeData="FileLogWriter"/>
<!-- Uncomment the below section and replace APPLICATION_NAME with the name of your application to write to the Application Event Log -->
<!--<add name="EventLog" type="System.Diagnostics.EventLogTraceListener" initializeData="APPLICATION_NAME"/> -->
</sharedListeners>
</system.diagnostics>
</configuration>
Is this even an issue? Will it present problems if I use this logger (explicitly stating its name) in multiple classes as opposed to the reflection?
Essentially, I'd just like to know why it's not working via the preferred method. Is my app.config incorrect? Am I doing something else incorrectly?
Thank you all!
You are only logging messages from VSED, your Reflection.MethodBase.GetCurrentMethod().DeclaringType is probably not VSED, but something.VSED. That is why your logger is not giving any output. See what the Reflection.MethodBase.GetCurrentMethod().DeclaringType is and make a logger with that name.
This will give the output from all your loggers:
<root>
<level value="DEBUG" />
<appender-ref ref="RollingLogFileAppender" />
</root>