I know the Chris Fulstow log4net.signalr project , this is a great idea if you want a non-working log, since it logs all messages from all requests. I would like to have something that recognizes the log messages by the request coming from them and is sent back to the appropriate browser.
Here is what I did in the application:
public class SignalRHubAppender:AppenderSkeleton { protected override void Append(log4net.Core.LoggingEvent loggingEvent) { if (HttpContext.Current != null) { var cookie = HttpContext.Current.Request.Cookies["log-id"]; if (null != cookie) { var formattedEvent = RenderLoggingEvent(loggingEvent); var context = GlobalHost.ConnectionManager.GetHubContext<Log4NetHub>(); context.Clients[cookie.Value].onLog(new { Message = formattedEvent, Event = loggingEvent }); } } } }
I am trying to attach a session id to a cookie, but this does not work on the same computer because the cookie is overwritten. here is the code that I use on the client to attach the event:
//start hubs $.connection.hub.start() .done(function () { console.log("hub subsystem running..."); console.log("hub connection id=" + $.connection.hub.id); $.cookie("log-id", $.connection.hub.id); log4netHub.listen(); });
As a result, only the last connected page displays log messages. I would like to know if there are any strategies to have the current connection identifier from the browser that initiates the current request, if one exists. I am also interested to know if there is a better design to achieve registration in the browser.
EDIT
I could create a cookie with a conditional name (e.g. log-id-someguid), but I'm wondering if there is anything smarter.
BOUNTY I decided to start a generosity on this issue, and I will additionally ask about architecture to find out if my strategy makes sense or not. I doubt that I use the hub in one โdirectionโ from server to client, and I use it to register actions that are not related to calls to the hub, but from other requests (potentially requests raised on other hubs), which is the right approach, having as a target the browser visible log4net appender?
source share