在我的工作中,我被要求在用 C# 编写的 ASP.NET Web API 2 中实现健康检查。我已经搜索过,但所有文档都是针对 ASP.NET Core 及其实现的,有人知道如何在经典/完整的 .NET Framework 中实现健康检查功能吗?
最佳答案
我同意伊戈尔。这是他建议的具体应用(显然,还有其他方法可以做到这一点,但这是我知道如何保持清晰并尊重关注点分离的最佳方法):
public class HealthController : ApiController
{
[HttpGet]
public IHttpActionResult Check()
{
// Add logic here to check dependencies
if (/* successful */)
{
return Ok();
}
return InternalServerError(); // Or whatever other HTTP status code is appropriate
}
}
我用过 Amazon CloudWatch过去,我对此很满意。那里会有其他服务可以为您执行此操作,但我对它们没有任何经验。
关于c# - 健康检查,ASP.NET Web API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62351410/