This commit is contained in:
Brennan 2015-03-04 20:54:18 -08:00
Родитель a56767186d
Коммит d149542f6a
6 изменённых файлов: 49 добавлений и 49 удалений

Просмотреть файл

@ -149,7 +149,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
{
if (Logger.IsEnabled(LogLevel.Verbose))
{
Logger.WriteVerbose(String.Format("Created DbCommand: CommandType={0}, CommandText={1}, Parameters={2}", command.CommandType, command.CommandText,
Logger.LogVerbose(String.Format("Created DbCommand: CommandType={0}, CommandText={1}, Parameters={2}", command.CommandType, command.CommandText,
command.Parameters.Cast<DbParameter>()
.Aggregate(string.Empty, (msg, p) => string.Format(CultureInfo.InvariantCulture, "{0} [Name={1}, Value={2}]", msg, p.ParameterName, p.Value)))
);
@ -175,7 +175,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
}
catch (Exception ex)
{
Logger.WriteWarning("Exception thrown by Task", ex);
Logger.LogWarning("Exception thrown by Task", ex);
throw;
}
}

Просмотреть файл

@ -129,7 +129,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
if (retryDelay > 0)
{
Logger.WriteVerbose(String.Format("{0}Waiting {1}ms before checking for messages again", LoggerPrefix, retryDelay));
Logger.LogVerbose(String.Format("{0}Waiting {1}ms before checking for messages again", LoggerPrefix, retryDelay));
Thread.Sleep(retryDelay);
}
@ -143,21 +143,21 @@ namespace Microsoft.AspNet.SignalR.SqlServer
}
catch (Exception ex)
{
Logger.WriteError(String.Format("{0}Error in SQL receive loop: {1}", LoggerPrefix, ex));
Logger.LogError(String.Format("{0}Error in SQL receive loop: {1}", LoggerPrefix, ex));
Faulted(ex);
}
if (recordCount > 0)
{
Logger.WriteVerbose(String.Format("{0}{1} records received", LoggerPrefix, recordCount));
Logger.LogVerbose(String.Format("{0}{1} records received", LoggerPrefix, recordCount));
// We got records so start the retry loop again
i = -1;
break;
}
Logger.WriteVerbose("{0}No records received", LoggerPrefix);
Logger.LogVerbose("{0}No records received", LoggerPrefix);
var isLastRetry = i == delays.Count - 1 && j == retryCount - 1;
@ -175,7 +175,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
// No records after all retries, set up a SQL notification
try
{
Logger.WriteVerbose("{0}Setting up SQL notification", LoggerPrefix);
Logger.LogVerbose("{0}Setting up SQL notification", LoggerPrefix);
recordCount = ExecuteReader(processRecord, command =>
{
@ -186,7 +186,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
if (recordCount > 0)
{
Logger.WriteVerbose("{0}Records were returned by the command that sets up the SQL notification, restarting the receive loop", LoggerPrefix);
Logger.LogVerbose("{0}Records were returned by the command that sets up the SQL notification, restarting the receive loop", LoggerPrefix);
i = -1;
break; // break the inner for loop
@ -198,7 +198,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
if (previousState == NotificationState.AwaitingNotification)
{
Logger.WriteError("{0}A SQL notification was already running. Overlapping receive loops detected, this should never happen. BUG!", LoggerPrefix);
Logger.LogError("{0}A SQL notification was already running. Overlapping receive loops detected, this should never happen. BUG!", LoggerPrefix);
return;
}
@ -207,7 +207,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
{
// Failed to change _notificationState from ProcessingUpdates to AwaitingNotification, it was already NotificationReceived
Logger.WriteVerbose("{0}The SQL notification fired before the receive loop returned, restarting the receive loop", LoggerPrefix);
Logger.LogVerbose("{0}The SQL notification fired before the receive loop returned, restarting the receive loop", LoggerPrefix);
i = -1;
break; // break the inner for loop
@ -215,7 +215,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
}
Logger.WriteVerbose("{0}No records received while setting up SQL notification", LoggerPrefix);
Logger.LogVerbose("{0}No records received while setting up SQL notification", LoggerPrefix);
// We're in a wait state for a notification now so check if we're disposing
lock (_stopLocker)
@ -228,7 +228,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
}
catch (Exception ex)
{
Logger.WriteError(String.Format("{0}Error in SQL receive loop: {1}", LoggerPrefix, ex));
Logger.LogError(String.Format("{0}Error in SQL receive loop: {1}", LoggerPrefix, ex));
Faulted(ex);
// Re-enter the loop on the last retry delay
@ -236,7 +236,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
if (retryDelay > 0)
{
Logger.WriteVerbose(String.Format("{0}Waiting {1}ms before checking for messages again", LoggerPrefix, retryDelay));
Logger.LogVerbose(String.Format("{0}Waiting {1}ms before checking for messages again", LoggerPrefix, retryDelay));
Thread.Sleep(retryDelay);
}
@ -247,7 +247,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
}
}
Logger.WriteVerbose("{0}Receive loop exiting", LoggerPrefix);
Logger.LogVerbose("{0}Receive loop exiting", LoggerPrefix);
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Disposing")]
@ -285,7 +285,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "sender", Justification = "Event handler")]
protected virtual void SqlDependency_OnChange(SqlNotificationEventArgs e, Action<DbDataReader, DbOperation> processRecord)
{
Logger.WriteInformation("{0}SQL notification change fired", LoggerPrefix);
Logger.LogInformation("{0}SQL notification change fired", LoggerPrefix);
lock (_stopLocker)
{
@ -300,7 +300,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
if (previousState == NotificationState.NotificationReceived)
{
Logger.WriteError("{0}Overlapping SQL change notifications received, this should never happen, BUG!", LoggerPrefix);
Logger.LogError("{0}Overlapping SQL change notifications received, this should never happen, BUG!", LoggerPrefix);
return;
}
@ -309,7 +309,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
// We're still in the original receive loop
// New updates will be retreived by the original reader thread
Logger.WriteVerbose("{0}Original reader processing is still in progress and will pick up the changes", LoggerPrefix);
Logger.LogVerbose("{0}Original reader processing is still in progress and will pick up the changes", LoggerPrefix);
return;
}
@ -321,15 +321,15 @@ namespace Microsoft.AspNet.SignalR.SqlServer
{
if (e.Info == SqlNotificationInfo.Update)
{
Logger.WriteVerbose(string.Format("{0}SQL notification details: Type={1}, Source={2}, Info={3}", LoggerPrefix, e.Type, e.Source, e.Info));
Logger.LogVerbose(string.Format("{0}SQL notification details: Type={1}, Source={2}, Info={3}", LoggerPrefix, e.Type, e.Source, e.Info));
}
else if (e.Source == SqlNotificationSource.Timeout)
{
Logger.WriteVerbose("{0}SQL notification timed out", LoggerPrefix);
Logger.LogVerbose("{0}SQL notification timed out", LoggerPrefix);
}
else
{
Logger.WriteError(string.Format("{0}Unexpected SQL notification details: Type={1}, Source={2}, Info={3}", LoggerPrefix, e.Type, e.Source, e.Info));
Logger.LogError(string.Format("{0}Unexpected SQL notification details: Type={1}, Source={2}, Info={3}", LoggerPrefix, e.Type, e.Source, e.Info));
Faulted(new SqlMessageBusException(String.Format(CultureInfo.InvariantCulture, Resources.Error_UnexpectedSqlNotificationType, e.Type, e.Source, e.Info)));
}
@ -338,7 +338,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
{
Debug.Assert(e.Info != SqlNotificationInfo.Invalid, "Ensure the SQL query meets the requirements for query notifications at http://msdn.microsoft.com/en-US/library/ms181122.aspx");
Logger.WriteError(string.Format("{0}SQL notification subscription error: Type={1}, Source={2}, Info={3}", LoggerPrefix, e.Type, e.Source, e.Info));
Logger.LogError(string.Format("{0}SQL notification subscription error: Type={1}, Source={2}, Info={3}", LoggerPrefix, e.Type, e.Source, e.Info));
if (e.Info == SqlNotificationInfo.TemplateLimit)
{
@ -381,29 +381,29 @@ namespace Microsoft.AspNet.SignalR.SqlServer
return false;
}
Logger.WriteVerbose("{0}Starting SQL notification listener", LoggerPrefix);
Logger.LogVerbose("{0}Starting SQL notification listener", LoggerPrefix);
try
{
if (SqlDependency.Start(ConnectionString))
{
Logger.WriteVerbose("{0}SQL notification listener started", LoggerPrefix);
Logger.LogVerbose("{0}SQL notification listener started", LoggerPrefix);
}
else
{
Logger.WriteVerbose("{0}SQL notification listener was already running", LoggerPrefix);
Logger.LogVerbose("{0}SQL notification listener was already running", LoggerPrefix);
}
return true;
}
catch (InvalidOperationException)
{
Logger.WriteInformation("{0}SQL Service Broker is disabled, disabling query notifications", LoggerPrefix);
Logger.LogInformation("{0}SQL Service Broker is disabled, disabling query notifications", LoggerPrefix);
_notificationState = NotificationState.Disabled;
return false;
}
catch (Exception ex)
{
Logger.WriteError(String.Format("{0}Error starting SQL notification listener: {1}", LoggerPrefix, ex));
Logger.LogError(String.Format("{0}Error starting SQL notification listener: {1}", LoggerPrefix, ex));
return false;
}
@ -423,13 +423,13 @@ namespace Microsoft.AspNet.SignalR.SqlServer
#if ASPNET50
try
{
Logger.WriteVerbose("{0}Stopping SQL notification listener", LoggerPrefix);
Logger.LogVerbose("{0}Stopping SQL notification listener", LoggerPrefix);
SqlDependency.Stop(ConnectionString);
Logger.WriteVerbose("{0}SQL notification listener stopped", LoggerPrefix);
Logger.LogVerbose("{0}SQL notification listener stopped", LoggerPrefix);
}
catch (Exception stopEx)
{
Logger.WriteError(String.Format("{0}Error occured while stopping SQL notification listener: {1}", LoggerPrefix, stopEx));
Logger.LogError(String.Format("{0}Error occured while stopping SQL notification listener: {1}", LoggerPrefix, stopEx));
}
#endif
}

Просмотреть файл

@ -28,7 +28,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2100:Review SQL queries for security vulnerabilities", Justification = "Query doesn't come from user code")]
public void Install()
{
_logger.WriteInformation("Start installing SignalR SQL objects");
_logger.LogInformation("Start installing SignalR SQL objects");
if (!IsSqlEditionSupported(_connectionString))
{
@ -46,7 +46,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
var operation = new DbOperation(_connectionString, script, _logger);
operation.ExecuteNonQuery();
_logger.WriteInformation("SignalR SQL objects installed");
_logger.LogInformation("SignalR SQL objects installed");
}
private bool IsSqlEditionSupported(string connectionString)

Просмотреть файл

@ -59,7 +59,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
_configuration = configuration;
_dbProviderFactory = dbProviderFactory;
_logger = loggerFactory.Create<SqlMessageBus>();
_logger = loggerFactory.CreateLogger<SqlMessageBus>();
ThreadPool.QueueUserWorkItem(Initialize);
}
@ -78,7 +78,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
protected override void Dispose(bool disposing)
{
_logger.WriteInformation("SQL message bus disposing, disposing streams");
_logger.LogInformation("SQL message bus disposing, disposing streams");
for (var i = 0; i < _streams.Count; i++)
{
@ -93,7 +93,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
private void Initialize(object state)
{
// NOTE: Called from a ThreadPool thread
_logger.WriteInformation(String.Format("SQL message bus initializing, TableCount={0}", _configuration.TableCount));
_logger.LogInformation(String.Format("SQL message bus initializing, TableCount={0}", _configuration.TableCount));
while (true)
{
@ -111,7 +111,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
OnError(i, ex);
}
_logger.WriteError("Error trying to install SQL server objects, trying again in 2 seconds: {0}", ex);
_logger.LogError("Error trying to install SQL server objects, trying again in 2 seconds: {0}", ex);
// Try again in a little bit
Thread.Sleep(2000);
@ -150,7 +150,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
{
OnError(streamIndex, ex);
_logger.WriteWarning("Exception thrown by Task", ex);
_logger.LogWarning("Exception thrown by Task", ex);
Thread.Sleep(2000);
StartReceiving(streamIndex);
}

Просмотреть файл

@ -67,7 +67,7 @@ namespace Microsoft.AspNet.SignalR.SqlServer
_dbOperation.Dispose();
}
_disposed = true;
_logger.WriteInformation("{0}SqlReceiver disposed", _loggerPrefix);
_logger.LogInformation("{0}SqlReceiver disposed", _loggerPrefix);
}
}
@ -89,14 +89,14 @@ namespace Microsoft.AspNet.SignalR.SqlServer
_lastPayloadId = (long?)lastPayloadIdOperation.ExecuteScalar();
Queried();
_logger.WriteVerbose(String.Format("{0}SqlReceiver started, initial payload id={1}", _loggerPrefix, _lastPayloadId));
_logger.LogVerbose(String.Format("{0}SqlReceiver started, initial payload id={1}", _loggerPrefix, _lastPayloadId));
// Complete the StartReceiving task as we've successfully initialized the payload ID
tcs.TrySetResult(null);
}
catch (Exception ex)
{
_logger.WriteError(String.Format("{0}SqlReceiver error starting: {1}", _loggerPrefix, ex));
_logger.LogError(String.Format("{0}SqlReceiver error starting: {1}", _loggerPrefix, ex));
tcs.TrySetException(ex);
return;
@ -126,16 +126,16 @@ namespace Microsoft.AspNet.SignalR.SqlServer
#if ASPNET50
_dbOperation.Changed += () =>
{
_logger.WriteInformation("{0}Starting receive loop again to process updates", _loggerPrefix);
_logger.LogInformation("{0}Starting receive loop again to process updates", _loggerPrefix);
_dbOperation.ExecuteReaderWithUpdates(ProcessRecord);
};
#endif
_logger.WriteVerbose(String.Format("{0}Executing receive reader, initial payload ID parameter={1}", _loggerPrefix, _dbOperation.Parameters[0].Value));
_logger.LogVerbose(String.Format("{0}Executing receive reader, initial payload ID parameter={1}", _loggerPrefix, _dbOperation.Parameters[0].Value));
_dbOperation.ExecuteReaderWithUpdates(ProcessRecord);
_logger.WriteInformation("{0}SqlReceiver.Receive returned", _loggerPrefix);
_logger.LogInformation("{0}SqlReceiver.Receive returned", _loggerPrefix);
}
#if ASPNET50
@ -147,15 +147,15 @@ namespace Microsoft.AspNet.SignalR.SqlServer
var id = record.GetInt64(0);
ScaleoutMessage message = SqlPayload.FromBytes(record);
_logger.WriteVerbose(String.Format("{0}SqlReceiver last payload ID={1}, new payload ID={2}", _loggerPrefix, _lastPayloadId, id));
_logger.LogVerbose(String.Format("{0}SqlReceiver last payload ID={1}, new payload ID={2}", _loggerPrefix, _lastPayloadId, id));
if (id > _lastPayloadId + 1)
{
_logger.WriteError(String.Format("{0}Missed message(s) from SQL Server. Expected payload ID {1} but got {2}.", _loggerPrefix, _lastPayloadId + 1, id));
_logger.LogError(String.Format("{0}Missed message(s) from SQL Server. Expected payload ID {1} but got {2}.", _loggerPrefix, _lastPayloadId + 1, id));
}
else if (id <= _lastPayloadId)
{
_logger.WriteInformation(String.Format("{0}Duplicate message(s) or payload ID reset from SQL Server. Last payload ID {1}, this payload ID {2}", _loggerPrefix, _lastPayloadId, id));
_logger.LogInformation(String.Format("{0}Duplicate message(s) or payload ID reset from SQL Server. Last payload ID {1}, this payload ID {2}", _loggerPrefix, _lastPayloadId, id));
}
_lastPayloadId = id;
@ -163,9 +163,9 @@ namespace Microsoft.AspNet.SignalR.SqlServer
// Update the Parameter with the new payload ID
dbOperation.Parameters[0].Value = _lastPayloadId;
_logger.WriteVerbose(String.Format("{0}Updated receive reader initial payload ID parameter={1}", _loggerPrefix, _dbOperation.Parameters[0].Value));
_logger.LogVerbose(String.Format("{0}Updated receive reader initial payload ID parameter={1}", _loggerPrefix, _dbOperation.Parameters[0].Value));
_logger.WriteVerbose(String.Format("{0}Payload {1} containing {2} message(s) received", _loggerPrefix, id, message.Messages.Count));
_logger.LogVerbose(String.Format("{0}Payload {1} containing {2} message(s) received", _loggerPrefix, id, message.Messages.Count));
Received((ulong)id, message);
}

Просмотреть файл

@ -48,14 +48,14 @@ namespace Microsoft.AspNet.SignalR.SqlServer
public Task Send(IList<Message> messages)
{
_logger.WriteVerbose(String.Format("{0}Saving payload with {1} messages(s) to SQL server", _loggerPrefix, messages.Count, _streamIndex));
_logger.LogVerbose(String.Format("{0}Saving payload with {1} messages(s) to SQL server", _loggerPrefix, messages.Count, _streamIndex));
return _sender.Send(messages);
}
public void Dispose()
{
_logger.WriteInformation(String.Format("{0}Disposing stream {1}", _loggerPrefix, _streamIndex));
_logger.LogInformation(String.Format("{0}Disposing stream {1}", _loggerPrefix, _streamIndex));
_receiver.Dispose();
}