I use a method to handle exceptions - internally it writes to a database, but when released to the web, the source code won't include the connection string necessary to write to the database. Instead it should write to a log file.
Is it possible to accommodate writing to logs when Foo.Private.dll is not present, but write to the database when it is?
//In Foo.Public.dll assembly
public class SimpleLogWriter
{
public virtual void LogError(Exception ex)
{
//Write to log file.
}
}
...
//In Foo.Private.dll assembly
public class ExtendedLogWriter : SimpleLogWriter
{
public override void LogError(Exception ex)
{
//Write to database
}
}
I had considered having both log classes implementing a shared interface (instead of extending and overriding) and creating some factory method to render it, but not sure how to validate the existence of an assembly or use its types without adding a reference, in which case the end-project would have a circular reference.
This sounds like a potential use case for the Managed Extensibility Framework (MEF), available in .NET 4.0.