This project has moved and is read-only. For the latest updates, please go here.


Log4netsends messages (to multiple destinations) and can be configured without having to restart the web service or application.
If you use log4net, you can turn logging on and off without having to recompile the code. You can also configure your plugin to use a remote logger, so that usage, logs, and possibly, errors could be submitted automatically.

Programming code sample

See for more details

Initial Code

In one class add the attribute
Using ... statements

// Load the configuration from the 'wateroneflow.logging.log4net' file
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "wateroneflow.logging.log4net", Watch = true)]

After the class definition:
  public class Service_1_0 : WebService, IService_1_0
      private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
     // if you want to log queries to a separate "file" or logging stream
      private static readonly ILog queryLog = LogManager.GetLogger("QueryLog");

Generally log an error message:
  log.Error("Cannot retrieve information from connection " + e.Message + spatialTableAdapter.Connection.DataSource);

 log.Fatal("Cannot retrieve information from connection " + e.Message + spatialTableAdapter.Connection.DataSource);

 log.Debug("Location Parameter:" + location.ToString());

or log a query (beware of nulls, so use C# Conditional Operator ( ?: ) and Null-Coalescing Operator ( ?? )
 queryLog.InfoFormat("Location: {0}  variable:{1} begin:{2} end{3}",  location ?? String.Empty, variable?? String.Empty,
beginDate?? string.Empty, endDate?? string.Empty) 

Last edited Oct 1, 2010 at 5:02 AM by valentinedwv, version 9


No comments yet.