I’m trying to write a log without having a configuration file by using Fluent API.
this is my code:
var builder = new ConfigurationSourceBuilder();
builder.ConfigureData()
.ForDatabaseNamed("Logging")
.ThatIs.ASqlDatabase()
.WithConnectionString(ConnectionString)
.AsDefault();
var configSource = new DictionaryConfigurationSource();
builder.UpdateConfigurationWithReplace(configSource);
var logger = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>();
logger.Write("Test", "General");
when I run this it just says that
Activation error occured while trying to get instance of type LogWriter, key “”
what did I do wrong in configuration ?
There are 2 things missing:
EnterpriseLibraryContainer.CreateDefaultContainermethodHere’s how you create the container with the configuration information:
To configure logging using the Fluent API see Using the Fluent Configuration API.
The example from that article is:
If you wish to configure both the logging block to write to a database using the data access block you can also do it using the fluent interface: