I am building a logging DLL that will simplify EntLib 5 Logging Application Block. I am using ConfigurationSourceBuilder to configure the logging for my application. I currently have this:
var configBuilder = new ConfigurationSourceBuilder();
configBuilder.ConfigureLogging().WithOptions
.DoNotRevertImpersonation()
.LogToCategoryNamed("EventLog")
.WithOptions.SetAsDefaultCategory()
.SendTo.EventLog("Event Log Listener")
.FormatWithSharedFormatter("Text Formatter")
.ToLog("Application")
.LogToCategoryNamed("Email")
.SendTo.Email("Email Trace Listener")
.To(ToEmail)
.From(fromEmail)
.WithSubjectStart("Error:")
.UsingSmtpServer(SmtpServer)
.UsingSmtpServerPort(SmtpServerPort)
.Unauthenticated()
.FormatWithSharedFormatter("Text Formatter")
.LogToCategoryNamed("LogFile")
.SendTo.FlatFile("Flat File Trace Listener")
.ToFile(logFileName)
.WithHeader("------------------------------")
.WithFooter("------------------------------")
.FormatWithSharedFormatter("Text Formatter");
var configSource = new DictionaryConfigurationSource();
configBuilder.UpdateConfigurationWithReplace(configSource);
EnterpriseLibraryContainer.Current =
EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
The program will build and I will reference it in the main app. When it goes to set up the configuration it blows up with this error:
InvalidOperationException - The current type,
Microsoft.Practices.EnterpriseLibrary.Logging.Formatters.ILogFormatter,
is an interface and cannot be constructed. Are you missing a type mapping?
Just in case this matters, the main app is using Unity as an IoC. Do I need to resolve the DLL with Unity?
It looks to me like the issue is that you haven’t actually created a Formatter. You’ve referenced an existing formatter by name with the statement
.FormatWithSharedFormatter("Text Formatter").If you define a formatter using
FormatterBuilderthen it should be OK: