本文整理汇总了C#中EndpointConfiguration.DefineCriticalErrorAction方法的典型用法代码示例。如果您正苦于以下问题:C# EndpointConfiguration.DefineCriticalErrorAction方法的具体用法?C# EndpointConfiguration.DefineCriticalErrorAction怎么用?C# EndpointConfiguration.DefineCriticalErrorAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EndpointConfiguration
的用法示例。
在下文中一共展示了EndpointConfiguration.DefineCriticalErrorAction方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CriticalErrors
CriticalErrors(EndpointConfiguration endpointConfiguration)
{
#region DefiningCustomHostErrorHandlingAction
endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);
#endregion
}
示例2: CriticalErrors
CriticalErrors()
{
#region DefiningCustomHostErrorHandlingAction
EndpointConfiguration configuration = new EndpointConfiguration();
configuration.DefineCriticalErrorAction(OnCriticalError);
#endregion
}
示例3: CriticalError
public void CriticalError()
{
// ReSharper disable RedundantDelegateCreation
// ReSharper disable ConvertToLambdaExpression
#region 5to6CriticalError
EndpointConfiguration configuration = new EndpointConfiguration();
configuration.DefineCriticalErrorAction(
new Func<ICriticalErrorContext,Task>(context =>
{
// place you custom handling here
return Task.FromResult(0);
}));
#endregion
// ReSharper restore RedundantDelegateCreation
// ReSharper restore ConvertToLambdaExpression
}
示例4: CriticalErrorConfigAzure
CriticalErrorConfigAzure(EndpointConfiguration endpointConfiguration, ILog log)
{
#region DefineCriticalErrorActionForAzureHost
// Configuring how NServicebus handles critical errors
endpointConfiguration.DefineCriticalErrorAction(context =>
{
string output = $"Critical exception: '{context.Error}'";
log.Error(output, context.Exception);
if (Environment.UserInteractive)
{
Thread.Sleep(10000); // so that user can see on their screen the problem
}
string fatalMessage = $"The following critical error was encountered by NServiceBus:\n{context.Error}\nNServiceBus is shutting down.";
Environment.FailFast(fatalMessage, context.Exception);
return Task.FromResult(0);
});
#endregion
}
示例5: DefineCriticalErrorActionForAzureHost
public void DefineCriticalErrorActionForAzureHost()
{
EndpointConfiguration endpointConfiguration = new EndpointConfiguration();
#region DefineCriticalErrorActionForAzureHost
// Configuring how NServicebus handles critical errors
endpointConfiguration.DefineCriticalErrorAction(context =>
{
string errorMessage = $"We got a critical exception: '{context.Error}'\r\n{context.Exception}";
if (Environment.UserInteractive)
{
Thread.Sleep(10000); // so that user can see on their screen the problem
}
string fatalMessage = $"The following critical error was encountered by NServiceBus:\n{errorMessage}\nNServiceBus is shutting down.";
Environment.FailFast(fatalMessage, context.Exception);
return Task.FromResult(0);
});
#endregion
}
示例6: AsyncOnStart
async Task AsyncOnStart()
{
#region logging
PatternLayout layout = new PatternLayout
{
ConversionPattern = "%d %-5p %c - %m%n"
};
layout.ActivateOptions();
ConsoleAppender appender = new ConsoleAppender
{
Layout = layout,
Threshold = Level.Info
};
appender.ActivateOptions();
BasicConfigurator.Configure(appender);
LogManager.Use<Log4NetFactory>();
#endregion
#region create-config
EndpointConfiguration endpointConfiguration = new EndpointConfiguration();
#endregion
#region endpoint-name
endpointConfiguration.EndpointName("Samples.FirstEndpoint");
#endregion
#region container
ContainerBuilder builder = new ContainerBuilder();
//configure your custom services
//builder.RegisterInstance(new MyService());
IContainer container = builder.Build();
endpointConfiguration.UseContainer<AutofacBuilder>(c => c.ExistingLifetimeScope(container));
#endregion
#region serialization
endpointConfiguration.UseSerialization<JsonSerializer>();
#endregion
#region error
endpointConfiguration.SendFailedMessagesTo("error");
#endregion
#region transport
endpointConfiguration.UseTransport<MsmqTransport>();
#endregion
#region sagas
//Not required since Sagas are enabled by default in Version 5
#endregion
#region persistence
endpointConfiguration.UsePersistence<InMemoryPersistence, StorageType.Sagas>();
endpointConfiguration.UsePersistence<InMemoryPersistence, StorageType.Subscriptions>();
endpointConfiguration.UsePersistence<InMemoryPersistence, StorageType.Timeouts>();
#endregion
#region critical-errors
endpointConfiguration.DefineCriticalErrorAction(async context =>
{
// Log the critical error
logger.Fatal($"CRITICAL: {context.Error}", context.Exception);
await context.Stop();
// Kill the process on a critical error
string output = $"The following critical error was encountered by NServiceBus:\n{context.Error}\nNServiceBus is shutting down.";
Environment.FailFast(output, context.Exception);
});
#endregion
#region start-bus
endpointConfiguration.EnableInstallers();
endpoint = await Endpoint.Start(endpointConfiguration);
#endregion
await endpoint.SendLocal(new MyMessage());
}