This file contains hidden or 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
| <?xml version="1.0" encoding="utf-8"?> | |
| <log4net> | |
| <!-- Buffer 128 entries except with log level severity is WARN or higher. --> | |
| <appender name="buffer" type="log4net.Appender.BufferingForwardingAppender"> | |
| <bufferSize value="128" /> | |
| <appender-ref ref="console" /> | |
| <!--<lossy value="false" />--> | |
| <!--<OnlyFixPartialEventData value="true"/>--> | |
| <evaluator type="log4net.Core.LevelEvaluator"> |
This file contains hidden or 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
| // | |
| // Run this before anything NServiceBus related. If using | |
| // the host, put this in the constructor of the endpoint | |
| // configuration class. | |
| // | |
| log4net.Config.XmlConfigurator.Configure(); | |
| NServiceBus.Logging.LogManager.Use<NServiceBus.Log4Net.Log4NetFactory>(); |
This file contains hidden or 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.Globalization; | |
| using log4net.Util; | |
| namespace log4net | |
| { | |
| public static class LogExtentions | |
| { | |
| private static readonly Type ThisDeclaringType = typeof(LogExtentions); |
This file contains hidden or 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 class CustomerNotificationHandler | |
| : IHandleMessage<CustomerOrderNotification> | |
| , IHandleMessage<CustomerOrderStatusNotification> | |
| { | |
| public IBus Bus {get;set;} | |
| INotificationService GetClientForCustomer(string customerId) | |
| { | |
| return null; // Create a api client for your customer |
This file contains hidden or 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
| class Program | |
| { | |
| static Mutex SingleInstanceMutex = AcquireGlobalMutex("Receiver"); | |
| static Mutex AcquireGlobalMutex(string id, int durationInSeconds = 1) | |
| { | |
| var m = new Mutex(true, @"Global\" + id); | |
| var maxWaitDuration = TimeSpan.FromSeconds(durationInSeconds); | |
| if (!m.WaitOne(maxWaitDuration)) throw new InvalidOperationException("Failed to acquire mutex."); | |
| return m; |
This file contains hidden or 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 class SendDoSomethingTask : IWantToRunWhenEndpointStartsAndStops | |
| { | |
| ILog log = LogManager.GetLogger<SendDoSomethingTask>(); | |
| Task loop; | |
| CancellationTokenSource cancellationTokenSource; | |
| public Task Start(IMessageSession session) | |
| { | |
| cancellationTokenSource = new CancellationTokenSource(); | |
| loop = Task.Run(async () => |
This file contains hidden or 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
| var uptimeInSeconds = Stopwatch.GetTimestamp() / Stopwatch.Frequency; | |
| var uptime = TimeSpan.FromSeconds(uptimeInSeconds); | |
| Console.WriteLine(uptime); |
This file contains hidden or 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.Logging; | |
| using NServiceBus.Pipeline; | |
| /// <code> | |
| /// endpointConfiguration.Pipeline.Register(behavior: new LogDispatchedMessageIdBehavior(), description: LogDispatchedMessageIdBehavior.Description); | |
| /// </code> | |
| class LogDispatchedMessageIdBehavior : Behavior<IBatchDispatchContext> | |
| { |
This file contains hidden or 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.Diagnostics; | |
| using System.Linq; | |
| interface IMetrics | |
| { | |
| void UpdateDuration(Stopwatch value); | |
| } | |
| class MetricsViaPerformanceCounters : IDisposable, IMetrics |
This file contains hidden or 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 NServiceBus; | |
| using NServiceBus.Transport; | |
| class ExponentialBackoffPolicy | |
| { | |
| static Random random = new Random(); | |
| public static RecoverabilityAction Process(RecoverabilityConfig config, ErrorContext context) | |
| { |