DEV Community

MustafaSamedYeyin
MustafaSamedYeyin

Posted on

2 1

Asp.net core Handle Errors; Dosyaya Errors Loglamak Giriş.

İlk başta aşağıdaki yazımdaki adımları teker teker uygulayalım :

https://dev.to/mustafasamedyeyin/asp-net-core-logging-serilog-giris-200d

Daha sonra HomeController'ının Index action'ını aşağıdaki gibi değiştirelim :

public IActionResult Index()
        {
            throw new Exception(Environment.NewLine + Environment.NewLine + Environment.NewLine + "Bu öylesine fırlatılmış hata;");
            return View();
        }

Enter fullscreen mode Exit fullscreen mode

Daha sonra Error action'ınnı içini aşağıdaki gibi değiştirelim :

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
        public IActionResult Error()
        {

            var exHandlerFeature = HttpContext.Features.Get<IExceptionHandlerFeature>();
            var exception = exHandlerFeature.Error;
            Log.Error(exception,"Bir hata oluştu."); 

            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
        }

Enter fullscreen mode Exit fullscreen mode

Uygulamayı çalıştırdığınızda belirttiğiniz yolda aşağıdaki dosyalar ve loglar oluşacaktır :

Image description

Aşağıdaki linkteki her şeyi yaptıysanız seq'de de loglarını görebilirsiniz.

https://dev.to/mustafasamedyeyin/asp-net-core-logging-serilog-giris-200d

Bir dahaki yazımda görüşmek dileğiyle.

En iyi dileklerim ile.

Mustafa Samed Yeyin.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More