DotNetOpenAuth is popular open source library which simplifies implementation of own OAuth server (it also have other functionalities, like OpenID). The first thing which you will need when will use it is logger. DotNetOpenAuth may work with log4net – popular logging library for .Net. If it doesn’t finds log4net assembly it uses simple trace logger which writes records to the trace output (which you can read e.g. with DebugView utility). By default trace logger is switched off. In order to enable it you need to add the following section into your web.config file:
Trace logger may be good for local development environments, but it is not very useful on production where you don’t always monitor logs with external utilities. For production environment log4net is more suitable choice.
The problem however is that when log4net assembly is installed to the GAC DotNetOpenAuth can’t find it and thus uses trace logger (issue was found in all-in-one DotNetOpenAuth assembly of 18.104.22.168 version). First of all in this case we need to specify fully qualified assembly names in web.config’s sections for configuration of log4net:
But it is not enough. Another problem comes from DotNetOpenAuth.Loggers.Log4NetLogger.IsLog4NetPresent property:
Assembly.Load(“log4net”) call throws FileNotFoundException. In order to fix the problem attach custom handler to AppDomain.AssemblyResolve event (e.g. in Application_Start in Global.asax.cs or in http module. In last case ensure that it is done once) and specify fully qualified assembly name:
After that DotNetOpenAuth logging should work.