No, but its pretty easy to write one. We had exactly the same situation where we need to post errors to the server and use a webservice to do it. Here's a pretty simple one, but it was written for a previous version of Log4Net but should give general idea (btw, InitializeService is a method that was created to set security, urls, etc. on the webservice).

/// <summary>
/// Summary description for ServiceAppender.
/// </summary>
public class ServiceAppender : AppenderSkeleton
{
public ServiceAppender()
{
 //Do any intialization here.
}

#region Implementation of IOptionHandler

public override void ActivateOptions()
{
 base.ActivateOptions ();

 //Provide any checks based on Service config properties, if Service
 //config properties are valid initialize ServiceAppender.

 InitializeServiceConnection();
}


#endregion

#region Override implementation of AppenderSkeleton

protected override void Append(LoggingEvent loggingEvent)
{
 //Set any necessary loggingEvent properties.
//(e.g. loggingEvent.Properties[LoggingEvent.HostNameProperty] = SystemInfo.HostName;
 /* TODO */

 try
 {
  //Call the WebService Logger.
// TODO: Decide how to proceed. This normally is controlled from the App.Config file, // but if it gets changed to something less than a level of Error by someone // not knowing the ramifications, it could cause an enormous amount of traffic.

// TODO: I want to checkin a workable copy, I don't have rights to update manaslu with updated WebService. After updating manaslu then uncomment and checkin. //if (loggingEvent.Level.Name.ToUpper() == "ERROR" || loggingEvent.Level.Name.ToUpper() == "FATAL") _serviceLogging.RMSServiceLogger(loggingEvent.Level.Name, loggingEvent.RenderedMessage, Environment.UserName, Environment.UserDomainName, ((AppBaseLoader)AppLoader.Instance).PersonSystemUserGuid, SystemInfo.HostName);
 }
 catch(Exception exc)
 {
ErrorHandler.Error("Unable to send loggingEvent to Logging Service", exc, ErrorCodes.WriteFailure);
 }
}


protected override bool RequiresLayout
{
 get { return false; }
}


public override void OnClose()
{
 base.OnClose ();

 //Release any resource that were needed.

}

#endregion

#region Private Methods

private void InitializeServiceConnection()
{
 try
 {
  //Code any Service initialization needed for ServiceAppender to work.
  //This is called from ActiveOptions.
  //Instantiate the WebService.
  if (_serviceLogging == null)
_serviceLogging = (Logging.LoggingService)InitializeService(typeof(Logging.LoggingService));
 }
 catch(Exception exc)
 {
  // TODO: Add Service name to error message.
ErrorHandler.Error("Could not initialize the service", exc, ErrorCodes.GenericFailure);

  // TODO: Reset the Service object to a known state if needed.
 }
}

#endregion

#region Fields

private Logging.LoggingService _serviceLogging = null;

#endregion

----- Original Message ----- From: "Billy Barnum" <[EMAIL PROTECTED]>
To: <[email protected]>
Sent: Sunday, January 15, 2006 5:27 PM
Subject: Is there anything resembling a "WebServicesAppender"?


I've gotten pretty familiar with the file, smtp, adonet, and eventlog
appenders, and have even written my own simple extensions. Now I'm being
asked to make log4net logging happen over the public internet from a .NET
Winforms client app, and I'm on unfamiliar ground.

The client is a .NET Winforms app that will do some work locally and hit up servers over http via .NET web services for other work, but log entries must be made to the central servers. My customer doesn't want to log locally and
then have users email local logs; they want to see errors and info entries
as they happen, or pretty soon thereafter. Ultimately, log entries are to be
written to NTFS files a la FileAppender.

I'm talking about something resembling a "Web Services Appender", methinks.

Is there some relatively easy way to achieve this with RemotingAppender and an almost-empty server host in IIS that just passes everything through via a
server-side log4net config file that names a FileAppender? Or is there
another, better approach?

I'm looking for general advice, samples, links to other resources - anything at all. Grateful for whatever tidbits I can get that don't take up too much
of folks' time. Thanks in advance.

-BillyB


Reply via email to