I understand why you do not want to pollute your business code with dependency on a third-party API.
However, it is also a fact that System.Diagnostics.Trace is not as flexible as the API provided by other logging frameworks such as EntLib and Log4Net.
I developed an internal API that relies heavily on log4net, which uses a provider model design pattern to provide a thin shell over any suitable logging framework. I have providers for System.Diagnostics.Trace, log4net and EntLib. The basic concept is very similar to the Common Infrastructure for.NET Protocol Library .
Thus, your business code depends only on your own internal API, and the logging environment can be selected at runtime using the configuration.
Of course, you can achieve what you want by sticking to System.Diagnostics.Trace and write your own TraceListeners for SMTP ( See this CodeProject example ) or shafts. Or write your own TraceListener, which redirects to a registration framework such as Log4Net, which then gives you access to the registrars supported by this infrastructure.
source share