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 static void LogWebDiagnostic(string product, string layer, string message, Dictionary <string, object> diagnosticInfo = null) { var writeDiagnostics = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableDiagnostics"]); if (!writeDiagnostics) // doing this to avoid going through all the data - user, session, etc. { return; } var webInfo = GetWebLoggingData(out string userId, out string userName, out string location); if (diagnosticInfo != null) { foreach (var key in diagnosticInfo.Keys) { webInfo.Add(key, diagnosticInfo[key]); } } var diagInfo = new LogDetail() { Product = product, Layer = layer, Location = location, UserId = userId, UserName = userName, Hostname = Environment.MachineName, CorrelationId = HttpContext.Current.Session.SessionID, Message = message, AdditionalInfo = webInfo }; McsLogger.WriteDiagnostic(diagInfo); }