static void Main(string[] args) { Serilog.Debugging.SelfLog.Enable(Console.Error); if (args is null) { throw new ArgumentNullException(nameof(args)); } var fd = GetLogDetail("starting application", null); McsLogger.WriteDiagnostic(fd); new PerfTracker("FloggerConsole_Execution", "", fd.UserName, fd.Location, fd.Product, fd.Layer); try { var ex = new Exception("Something bad has happened!"); ex.Data.Add("input param", "nothing to see here"); throw ex; } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { fd = GetLogDetail("", ex); McsLogger.WriteError(fd); } #pragma warning restore CA1031 // Do not catch general exception types var connStr = ConfigurationManager.ConnectionStrings["LogConnection"].ConnectionString; using (var db = new SqlConnection(connStr)) { db.Open(); try { var rawAdoSp = new SqlCommand("CreateNewCustomer", db) { CommandType = System.Data.CommandType.StoredProcedure }; rawAdoSp.Parameters.Add(new SqlParameter("@Name", "waytoolongforitsowngood")); rawAdoSp.Parameters.Add(new SqlParameter("@TotalPurchases", 12000)); rawAdoSp.Parameters.Add(new SqlParameter("@TotalReturns", 100.50M)); rawAdoSp.ExecuteNonQuery(); rawAdoSp.Dispose(); var sp = new MCS.Logging.DotNetFramework.Data.CustomAdo.StoredProcedure(db, "CreateNewCustomer"); sp.SetParam("@Name", "waytoolongforitsowngood"); sp.SetParam("@TotalPurchases", 12000); sp.SetParam("@TotalReturns", 100.50M); sp.ExecNonQuery(); } #pragma warning disable CA1031 // Do not catch general exception types catch (Exception ex) { var efd = GetLogDetail("", ex); McsLogger.WriteError(efd); } #pragma warning restore CA1031 // Do not catch general exception types } Console.ReadKey(); }
public override void Log(ExceptionLoggerContext context) { var dict = new Dictionary <string, object>(); string userId, userName; var user = context.RequestContext.Principal as ClaimsPrincipal; Helpers.GetUserData(dict, user, out userId, out userName); string location; Helpers.GetLocationForApiCall(context.RequestContext, dict, out location); var errorId = Guid.NewGuid().ToString(); // This is here because the Logger is called BEFORE the Handler in the //Web API exception pipeline context.Exception.Data.Add("ErrorId", errorId); var logEntry = new LogDetail() { CorrelationId = errorId, Product = _productName, Layer = "API", Location = location, Hostname = Environment.MachineName, Exception = context.Exception, UserId = userId, UserName = userName, AdditionalInfo = dict }; McsLogger.WriteError(logEntry); }
public static void LogWebError(string product, string layer, Exception ex) { var webInfo = GetWebLoggingData(out string userId, out string userName, out string location); var errorInformation = new LogDetail() { Product = product, Layer = layer, Location = location, UserId = userId, UserName = userName, Hostname = Environment.MachineName, CorrelationId = HttpContext.Current.Session?.SessionID, Exception = ex, AdditionalInfo = webInfo }; McsLogger.WriteError(errorInformation); }