Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Create a tracesource per type that traces.

- Added tracing to asp.net samples for the TransportHeartBeat.
  • Loading branch information...
commit f172830d4ff1cca1c69a5745c8aa324b57e606ba 1 parent 58e64c1
@davidfowl davidfowl authored
View
3  .gitignore
@@ -22,4 +22,5 @@ PublishProfiles/
*.pidb
*.userprefs
*DS_Store
-*.ncrunchsolution
+*.ncrunchsolution
+server.log
View
14 SignalR/Connection.cs
@@ -45,6 +45,14 @@ private IEnumerable<string> Signals
}
}
+ private TraceSource Trace
+ {
+ get
+ {
+ return _trace["SignalR.Connection"];
+ }
+ }
+
public virtual Task Broadcast(object value)
{
return Send(_baseSignal, value);
@@ -57,7 +65,7 @@ public virtual Task Send(string signal, object value)
public Task<PersistentResponse> ReceiveAsync(CancellationToken timeoutToken)
{
- _trace.Source.TraceInformation("Connection: Waiting for new messages");
+ Trace.TraceInformation("Waiting for new messages");
return _messageBus.GetMessages(Signals, null, timeoutToken)
.Then(result => GetResponse(result));
@@ -65,7 +73,7 @@ public Task<PersistentResponse> ReceiveAsync(CancellationToken timeoutToken)
public Task<PersistentResponse> ReceiveAsync(string messageId, CancellationToken timeoutToken)
{
- _trace.Source.TraceInformation("Connection: Waiting for messages from {0}.", messageId);
+ Trace.TraceInformation("Waiting for messages from {0}.", messageId);
return _messageBus.GetMessages(Signals, messageId, timeoutToken)
.Then(result => GetResponse(result));
@@ -92,7 +100,7 @@ private PersistentResponse GetResponse(MessageResult result)
PopulateResponseState(response);
- _trace.Source.TraceInformation("Connection: Connection '{0}' received {1} messages, last id {2}", _connectionId, result.Messages.Count, result.LastMessageId);
+ Trace.TraceInformation("Connection '{0}' received {1} messages, last id {2}", _connectionId, result.Messages.Count, result.LastMessageId);
return response;
}
View
10 SignalR/Hubs/HubDispatcher.cs
@@ -32,6 +32,14 @@ public HubDispatcher(string url)
_url = url;
}
+ protected override TraceSource Trace
+ {
+ get
+ {
+ return _trace["SignalR.HubDispatcher"];
+ }
+ }
+
public override void Initialize(IDependencyResolver resolver)
{
_proxyGenerator = resolver.Resolve<IJavaScriptProxyGenerator>();
@@ -202,7 +210,7 @@ private IHub CreateHub(IRequest request, HubDescriptor descriptor, string connec
}
catch (Exception ex)
{
- _trace.Source.TraceInformation("Error creating hub {0}. " + ex.Message, descriptor.Name);
+ Trace.TraceInformation("Error creating hub {0}. " + ex.Message, descriptor.Name);
if (throwIfFailedToCreate)
{
View
2  SignalR/Infrastructure/ITraceManager.cs
@@ -5,6 +5,6 @@ namespace SignalR.Infrastructure
public interface ITraceManager
{
SourceSwitch Switch { get; }
- TraceSource Source { get; }
+ TraceSource this[string name] { get; }
}
}
View
18 SignalR/Infrastructure/TraceManager.cs
@@ -1,16 +1,30 @@
-using System.Diagnostics;
+using System;
+using System.Collections.Concurrent;
+using System.Diagnostics;
namespace SignalR.Infrastructure
{
public class TraceManager : ITraceManager
{
+ private readonly ConcurrentDictionary<string, TraceSource> _sources = new ConcurrentDictionary<string, TraceSource>(StringComparer.OrdinalIgnoreCase);
+
public TraceManager()
{
Switch = new SourceSwitch("SignalRSwitch");
- Source = new TraceSource("SignalRSource", SourceLevels.Off) { Switch = Switch };
}
public SourceSwitch Switch { get; private set; }
public TraceSource Source { get; private set; }
+
+ public TraceSource this[string name]
+ {
+ get
+ {
+ return _sources.GetOrAdd(name, key => new TraceSource(key, SourceLevels.Off)
+ {
+ Switch = Switch
+ });
+ }
+ }
}
}
View
26 SignalR/MessageBus/InProcessMessageBus.cs
@@ -87,12 +87,20 @@ public InProcessMessageBus(ITraceManager traceManager, bool garbageCollectMessag
}
}
+ private TraceSource Trace
+ {
+ get
+ {
+ return _trace["SignalR.InProcessMessageBus"];
+ }
+ }
+
public Task<MessageResult> GetMessages(IEnumerable<string> eventKeys, string id, CancellationToken timeoutToken)
{
if (String.IsNullOrEmpty(id))
{
// Wait for new messages
- _trace.Source.TraceInformation("MessageBus: New connection waiting for messages");
+ Trace.TraceInformation("New connection waiting for messages");
return WaitForMessages(eventKeys, timeoutToken, default(T));
}
@@ -106,13 +114,13 @@ public Task<MessageResult> GetMessages(IEnumerable<string> eventKeys, string id,
{
// BUG 24: Connection already has the latest message, so reset the id
// This can happen if the server is reset (appdomain or entire server incase of self host)
- _trace.Source.TraceInformation("MessageBus: Connection asking for message id {0} when the largest is {1}. Resetting id", id, _lastMessageId);
+ Trace.TraceInformation("Connection asking for message id {0} when the largest is {1}. Resetting id", id, _lastMessageId);
uuid = default(T);
}
else if (uuid.CompareTo(_lastMessageId) == 0)
{
// Connection already has the latest message, so start wating
- _trace.Source.TraceInformation("MessageBus: Connection waiting for new messages from id {0}", uuid);
+ Trace.TraceInformation("Connection waiting for new messages from id {0}", uuid);
return WaitForMessages(eventKeys, timeoutToken, uuid);
}
@@ -121,12 +129,12 @@ public Task<MessageResult> GetMessages(IEnumerable<string> eventKeys, string id,
if (messages.Any())
{
// Messages already in store greater than last received id so return them
- _trace.Source.TraceInformation("MessageBus: Connection getting messages from cache from id {0}", uuid);
+ Trace.TraceInformation("Connection getting messages from cache from id {0}", uuid);
return TaskAsyncHelper.FromResult(GetMessageResult(messages.OrderBy(msg => msg.Id).ToList()));
}
// Wait for new messages
- _trace.Source.TraceInformation("MessageBus: Connection waiting for new messages from id {0}", uuid);
+ Trace.TraceInformation("Connection waiting for new messages from id {0}", uuid);
return WaitForMessages(eventKeys, timeoutToken, uuid);
}
finally
@@ -148,7 +156,7 @@ public Task Send(string connectionId, string eventKey, object value)
// Only 1 save allowed at a time, to ensure messages are added to the list in order
message = new InMemoryMessage<T>(eventKey, value, GenerateId());
- _trace.Source.TraceInformation("MessageBus: Saving message {0} with eventKey '{1}' to cache on AppDomain {2}", message.Id, eventKey, AppDomain.CurrentDomain.Id);
+ Trace.TraceInformation("Saving message {0} with eventKey '{1}' to cache on AppDomain {2}", message.Id, eventKey, AppDomain.CurrentDomain.Id);
list.AddWithLock(message);
// Send to waiting callers.
@@ -182,11 +190,11 @@ private void Broadcast(string eventKey, InMemoryMessage<T> message)
if (delegates.Count == 0)
{
- _trace.Source.TraceInformation("MessageBus: Sending message {0} with eventKey '{1}' to 0 waiting connections", message.Id, eventKey);
+ Trace.TraceInformation("Sending message {0} with eventKey '{1}' to 0 waiting connections", message.Id, eventKey);
return;
}
- _trace.Source.TraceInformation("MessageBus: Sending message {0} with eventKey '{1}' to {2} waiting connections", message.Id, eventKey, delegates.Count);
+ Trace.TraceInformation("Sending message {0} with eventKey '{1}' to {2} waiting connections", message.Id, eventKey, delegates.Count);
foreach (var callback in delegates)
{
@@ -340,7 +348,7 @@ private void RemoveExpiredEntries(object state)
catch (Exception ex)
{
// Exception on bg thread, bad! Log and swallow to stop the process exploding
- Trace.TraceError("Error during InProcessMessageStore clean up on background thread: {0}", ex);
+ Trace.TraceInformation("Error during InProcessMessageStore clean up on background thread: {0}", ex);
}
finally
{
View
9 SignalR/PersistentConnection.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Threading.Tasks;
using SignalR.Infrastructure;
using SignalR.Transports;
@@ -40,6 +41,14 @@ public virtual void Initialize(IDependencyResolver resolver)
_initialized = true;
}
+ protected virtual TraceSource Trace
+ {
+ get
+ {
+ return _trace["SignalR.PersistentConnection"];
+ }
+ }
+
/// <summary>
/// Occurs when a data is received from a connection.
/// </summary>
View
23 SignalR/Transports/TransportHeartBeat.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Linq;
using System.Threading;
using SignalR.Infrastructure;
@@ -41,6 +42,14 @@ public TransportHeartBeat(IDependencyResolver resolver)
_configurationManager.HeartBeatInterval);
}
+ private TraceSource Trace
+ {
+ get
+ {
+ return _trace["SignalR.Transports.TransportHeartBeat"];
+ }
+ }
+
private void ProcessServerCommand(ServerCommand command)
{
switch (command.Type)
@@ -63,7 +72,7 @@ private void ProcessServerCommand(ServerCommand command)
/// <param name="connection">The connection to be added.</param>
public bool AddConnection(ITrackingConnection connection)
{
- _trace.Source.TraceInformation("TransportHeartBeat: Adding connection {0}", connection.ConnectionId);
+ Trace.TraceInformation("Adding connection {0}, url={1}", connection.ConnectionId, connection.Url);
var newMetadata = new ConnectionMetadata(connection);
ConnectionMetadata oldMetadata = null;
@@ -77,7 +86,7 @@ public bool AddConnection(ITrackingConnection connection)
if (oldMetadata != null)
{
- _trace.Source.TraceInformation("TransportHeartBeat: Connection {0} already exists and alive={1}. Closing previous connection id.", oldMetadata.Connection.ConnectionId, oldMetadata.Connection.IsAlive);
+ Trace.TraceInformation("Connection {0} already exists and alive={1}. Closing previous connection. url={2}", oldMetadata.Connection.ConnectionId, oldMetadata.Connection.IsAlive, oldMetadata.Connection.Url);
// Kick out the older connection. This should only happen when
// a previous connection attempt fails on the client side (e.g. transport fallback).
@@ -88,7 +97,7 @@ public bool AddConnection(ITrackingConnection connection)
}
else
{
- _trace.Source.TraceInformation("TransportHeartBeat: Connection {0} is new.", connection.ConnectionId);
+ Trace.TraceInformation("Connection {0} is new url={1}.", connection.ConnectionId, connection.Url);
}
// Set the initial connection time
@@ -102,7 +111,7 @@ public bool AddConnection(ITrackingConnection connection)
private void RemoveConnection(string connectionId)
{
- _trace.Source.TraceInformation("TransportHeartBeat: Removing connection {0}", connectionId);
+ Trace.TraceInformation("Removing connection {0}", connectionId);
// Remove the connection
ConnectionMetadata metadata;
@@ -141,7 +150,7 @@ private void Beat(object state)
{
if (Interlocked.Exchange(ref _running, 1) == 1)
{
- _trace.Source.TraceInformation("TransportHeartBeat: timer handler took longer than current interval");
+ Trace.TraceInformation("timer handler took longer than current interval");
return;
}
@@ -162,7 +171,7 @@ private void Beat(object state)
}
catch (Exception ex)
{
- _trace.Source.TraceInformation("TransportHeartBeat: SignalR error during transport heart beat on background thread: {0}", ex);
+ Trace.TraceInformation("SignalR error during transport heart beat on background thread: {0}", ex);
}
finally
{
@@ -210,7 +219,7 @@ private void CheckDisconnect(ConnectionMetadata metadata)
catch (Exception ex)
{
// Swallow exceptions that might happen during disconnect
- _trace.Source.TraceInformation("TransportHeartBeat: Raising Disconnect failed: {0}", ex);
+ Trace.TraceInformation("Raising Disconnect failed: {0}", ex);
}
}
View
32 samples/SignalR.Hosting.AspNet.Samples/Web.config
@@ -4,11 +4,29 @@
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
- <system.web>
- <compilation debug="true" targetFramework="4.0" />
- <httpRuntime requestValidationMode="4.0" />
- </system.web>
- <system.webServer>
- <modules runAllManagedModulesForAllRequests="true" />
- </system.webServer>
+ <system.web>
+ <compilation debug="true" targetFramework="4.0" />
+ <httpRuntime requestValidationMode="4.0" />
+ </system.web>
+ <system.webServer>
+ <modules runAllManagedModulesForAllRequests="true" />
+ </system.webServer>
+ <system.diagnostics>
+ <sources>
+ <source name="SignalR.Transports.TransportHeartBeat">
+ <listeners>
+ <add name="SignalR" />
+ </listeners>
+ </source>
+ </sources>
+ <switches>
+ <add name="SignalRSwitch" value="Information" />
+ </switches>
+ <sharedListeners>
+ <add name="SignalR"
+ type="System.Diagnostics.TextWriterTraceListener"
+ initializeData="server.log" />
+ </sharedListeners>
+ <trace autoflush="true"/>
+ </system.diagnostics>
</configuration>
Please sign in to comment.
Something went wrong with that request. Please try again.