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?.…

Devexpress Datebox date formatting in angular 6 with example

The Devexpress DateBox in Angular is a widget that displays the date and time in one of DevExtreme predefined formats or a format defined in an
external localization library, or a type in the required date/time value. In this article,
the i will provide you different date-format which we can set on DateBox to show date and time to user.

Following is the code snippet to add Datebox in your Angular form if the you want to capture only date

         displayFormat="EEEE, MMM dd" type="date" >  

Following is the custom formats we can set and depending upon its converted values will be shown.

 "dd-MM-yyyy" => 28-10-2018  
 "EEEE, MMM dd" => Sunday, Oct 28  
 "dd MMM yyyy EEEE" => 28 Oct 2018 Sunday  
 "dd-MM-yyyy EEEE" => 28-10-2018 Sunday  

alternatively you can change the format as way you want

Following is the code snippet to add Datebox in your Angular form if the you want to capture date and time. we just need to change "type" attribute to "datetime".

         displayFormat="EEEE, MMM dd hh:mm:ss a" type="datetime" >  

Following is the custom formats for date & time we can set and depending upon formats its converted values will be shown to user.

 "EEEE, MMM dd hh:mm:ss a" => Sunday, Oct 28 12:20:31 PM  
 "dd-MM-yyyy hh:mm:ss a" => 28-10-2018 12:20:31 PM  

if you want to show the format in 24 hours you can use following strings

 "EEEE, MMM dd HH:mm:ss" => Sunday, Oct 28 16:24:10  
 "dd-MM-yyyy HH:mm:ss" => 28-10-2018 16:24:10  

I have given enough example of all possible format strings which you can change according to your need if you want.

Please provide me feedback if you want i am eagerly waiting for your comments.

Hope this will solve your query.


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