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

Add Comma automatically while entering amounts in textbox using Javascript

Use following javascript function to add comma in numerics input in textbox


function Comma(Num)
 {
       Num += '';
       Num = Num.replace(/,/g, '');

       x = Num.split('.');
       x1 = x[0];

       x2 = x.length > 1 ? '.' + x[1] : '';

       
         var rgx = /(\d)((\d)(\d{2}?)+)$/;

       while (rgx.test(x1))

       x1 = x1.replace(rgx, '$1' + ',' + '$2');
     
       return x1 + x2;       
        
 }

Use following event of input textbox to call above function

onkeyup = "javascript:this.value=Comma(this.value);"

Comments

  1. This doesn't work as it should.
    It works ok for the first thousand - a comma is inserted after entering 1000 - but when you continue entering numbers after that, it inserts consecutive commas after 2 digits, not 3, so you get something like this: 10,00,000 - where it should be: 1,000,000

    Did you test this with more than 4 digits?

    ReplyDelete
    Replies
    1. Thank you for your valuable comment

      i will look into the issue and update this post soon

      Delete
    2. just replace the regular expression with this:

      var rgx = /(\d)((\d{3}?)+)$/;

      Delete
  2. i need in asp.net textbox when type amount 12000 out should come in 12,000 likes this

    ReplyDelete

Post a Comment

Popular posts from this blog

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

Devexpress Datebox date formatting in angular 6 with example