This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Concurrent; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using NServiceBus.Features; | |
using NServiceBus.Logging; | |
using NServiceBus.Pipeline; | |
class LogIncomingMessageId : Feature | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading.Tasks; | |
using NServiceBus.Features; | |
using NServiceBus.Logging; | |
using NServiceBus.Pipeline; | |
class LogIncomingServiceControlRetry : Feature | |
{ | |
static readonly ILog Log = LogManager.GetLogger<LogIncomingServiceControlRetry>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// endpointConfiguration.Pipeline.Register(new LogDuplicateMessageId(),nameof(LogDuplicateMessageId)); | |
// | |
// NOTE: DOES NOT RELEASE MEMORY. Dictionary will grow indefinitely. ONLY FOR TESTING! | |
// | |
class LogDuplicateMessageId : IBehavior<IIncomingPhysicalMessageContext, IIncomingPhysicalMessageContext> | |
{ | |
static readonly BlockingCollection<string> Logs = new BlockingCollection<string>(); | |
static LogMessageId() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MIT , Inspired by https://softwareengineering.stackexchange.com/questions/149346/logging-asynchronously-how-should-it-be-done | |
using System; | |
using System.Collections.Concurrent; | |
using System.Threading.Tasks; | |
class AsyncConsoleLogger | |
{ | |
static readonly BlockingCollection<string> Logs = new BlockingCollection<string>(); | |
static AsyncConsoleLogger() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// endpointConfiguration.RegisterComponents(c=>c.ConfigureComponent<ExtendLoggerScopeWithMessageData>(DependencyLifecycle.SingleInstance)); | |
// endpointConfiguration.Pipeline.Register(b=>b.Build<ExtendLoggerScopeWithMessageData>(),nameof(ExtendLoggerScopeWithMessageData)); | |
// | |
using System; | |
using System.Collections.Generic; | |
using System.Threading.Tasks; | |
using NServiceBus; | |
using NServiceBus.Pipeline; | |
using Microsoft.Extensions.Logging; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Source: https://stackoverflow.com/a/24031467/199551 | |
public static string CreateMD5(string input) | |
{ | |
// Use input string to calculate MD5 hash | |
using (var md5 = System.Security.Cryptography.MD5.Create()) | |
{ | |
var inputBytes = System.Text.Encoding.ASCII.GetBytes(input); | |
var hashBytes = md5.ComputeHash(inputBytes); | |
// Convert the byte array to hexadecimal string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static class StringExt | |
{ | |
public static string? Truncate(this string? value, int maxLength) | |
{ | |
if (value == null) return value; | |
return value.Length <= maxLength ? value : string.Concat(value.AsSpan(0, maxLength - 1), "…"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ObjectExtension | |
{ | |
public static T Do<T>(this T instance, Action<T> x) | |
{ | |
x?.Invoke(instance); | |
return instance; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using NServiceBus; | |
using NServiceBus.Logging; | |
using NServiceBus.Raw; | |
using NServiceBus.Routing; | |
using NServiceBus.Transport; | |
CancellationTokenSource cts = new(); | |
Console.CancelKeyPress += (s, ea) => | |
{ | |
ea.Cancel = true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NServiceBus v8 will have improved support for cooperative cancellation. | |
// | |
// Register behavior: | |
// | |
// endpointConfiguration.Pipeline.Register(new CancellationTimeoutBehavior(TimeSpan.FromSeconds(5)), nameof(CancellationTimeoutBehavior)); | |
// | |
using System; | |
using System.Threading; | |
using System.Threading.Tasks; |