|
|
|
|
|
|
|
|
|
|
The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.
| Author |
Messages |
|
Billy Barnum
 |
| 01/16/2006 12:27 AM |
|
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
|
|
|
|
|
Ron Grabowski
 |
|
Hollywood
 |
| 01/16/2006 3:04 AM |
|
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 |
|
|
|
|
Georg Jansen
 |
| 01/16/2006 3:37 AM |
|
Billy,
Since web services are (relatively) slow, I would consider breaking this into two different processes. And do the web services call in a separate thread or process (depending on how performance critical this is).
Hollywoods code could probably be modified to start a separate thread to invoke the web service. You could also make the appender “buffered” and send several log events on the same time.
Another approach would be to store the log events on a kind of a queue (for example a file or a database table), and write a small program that consumes this queue and invokes the web service.
I realize that it is several different approaches to solve this, so this was just my $0.02.
Best regards
Georg
http://www.l4ndash.com - Log4Net Dashboard / Log Viewer |
|
|
|
|
Hollywood
 |
| 01/16/2006 5:18 AM |
|
Yes, we only use it on error and fatal messages, so usually its not that time consuming. Also its set to use an async call so it doesn't wait for a return message. That all being said, Georg is right about the relative slowness of the web services.
|
|
|
|
|
mailing@wallis.ca
 |
| 02/01/2006 7:29 PM |
|
|
I looked at this a while back and wrote my own web services appender. I first wrote it to send a fixed set of log parameters, but then you have a problem if you ever write exensions to log4net and your set of parameters changes. You would also have to change your web service methods each time. Then I tried to send over the log4net event object itself, but ran into serialization issues. Maybe others got this to work, but I ended up scrapping this approach.
I found .NET Remoting to be so much easier to deal with. If you have a .NET client and .NET server then you can use binary Remoting over TCP (as opposed to SOAP), which offers better performance and you don't need to worry about serialization. To make it even easier, if you look at the sample code in the log4net distribution, you will find a .NET Remoting server and a full example. This server also uses log4net, so on the receiving end you use log4net to log the events, meaning you can log them to files, databases, or whatever you want.
I have been using this approach for almost a year now. I have a bunch of application servers that use .NET Remoting appenders to log to a centralized cluster of "logging servers". These logging servers run the .NET Remoting Server (I run it as an NT service), listen on a port for incoming events, and when events are received it uses log4net to route the events to final destination (usually a database).
I actually wrote my own .NET Remoting appender that would make the calls asynchronous, but this was with 1.2.8, and I believe 1.2.9 has asynchronous built in with the .NET Remoting appender. I think the only case where you would want to use a web service appender instead of Remoting is either when your environment is not all .NET-based, or you can only open port 80 on your firewall (.NET remoting requires a port other than 80 to be open).
Simon.
-----Original message-----
From: "Billy Barnum" bbarnum@spamcop.net
Date: Sun, 15 Jan 2006 23:30:18 -0800
To: log4net-user@logging.apache.org
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
>
|
|
|
|
|
UweKeim Posts:2
 |
| 12/27/2006 7:31 AM |
|
Also, see http://www-128.ibm.com/developerworks/webservices/library/ws-log4j.html For an example for Log4J. |
|
|
|
|
UweKeim Posts:2
 |
| 12/27/2006 11:22 PM |
|
Yesterday I posted an Article to CodeProject based on the sample in this topic. Maybe it helps someone:
http://www.codeproject.com/useritems/Log4NetWebServiceAppender.asp
Enjoy :-). |
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|
|
|
|
|
|
|
|
|
|
Log4Net Dashboard
Log analysis and monitoring made easy!
Log4Net Dashboard is a log viewer that can read log statements from a variety of logging output targets.

Check it out!
On the demonstration site you can try it with live data.
|