Log exception to file in c# .net core application explained

In production environment when any bug gets reported at that time as developer wants to get the exception details of bug to resolve the issue on high priority.
In some case there might be situation where exception is not logged in table but developer wants to check the bug immediately. for that purpose we need to write the
exception details including stack trace of bug in file. To implement this easily i am going to demonstrate the implementation of custom logging in file as below.

First we need to construct the exception and logger method in custom logger class as shown below.


public class CustomLogger { public static List<string> ConstructExceptionDetails(Exception ex,string FunctionName) { return new List<string>() { $"{DateTime.Now} - {FunctionName}", $"Exception: {ex.Message}", $"StackTrace: {ex.StackTrace}", $"InnerException: {ex.InnerException?.…

System.Security.SecurityException: Request failed. issue on web server [resolved]

While hosting your website on shared hosting server you might get the System.Security.SecurityException: Request failed issue which will give you below stack trace on landing page of the website.

Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.



  • You can add below code to your Application web.config file to resolve it permanently

 
<system.web>
    <customErrors mode="Off"/>
    <trust level="Full" />
</system.web>
 
 
  • This issue might occur in the case when server does not have higher version of .Net framework installed. suppose your application is developed to work with 4.5 run-time framework but the same version is not installed on the server. You can ask your web hosting provider to install the required version on the server so that your website will work as expected.

You can refer below Microsoft support post for detailed information on this issue.

 https://support.microsoft.com/en-us/help/555466

Comments

  1. BlueHost is the best website hosting provider with plans for all of your hosting needs.

    ReplyDelete

Post a Comment

Popular posts from this blog

Restore the lost focus of Auto post back controls in asp.net update Panel control

Add Comma automatically while entering amounts in textbox using Javascript

Devexpress Datebox date formatting in angular 6 with example