/// <summary> /// Exceptionを指定し、ログを出力します。 /// </summary> /// <param name="logTypeId"></param> /// <param name="message"></param> public void WriteLog(Exception e) { using (HContext context = new HContext()) { Log log = new Log(); log.LogTypeId = MstLogTypes.Error; log.Message = e.Message; log.Contents = e.StackTrace; log.DateCreated = DateTime.Now; context.Logs.Add(log); context.SaveChanges(); if (e.InnerException != null) { Log innerLog = new Log(); innerLog.LogTypeId = MstLogTypes.Error; innerLog.Message = e.InnerException.Message; innerLog.Contents = e.InnerException.StackTrace; innerLog.DateCreated = DateTime.Now; context.Logs.Add(innerLog); context.SaveChanges(); } } }
/// <summary> /// ログ種別とメッセージを指定し、ログを出力します。 /// </summary> /// <param name="logTypeId"></param> /// <param name="message"></param> public void WriteLog(MstLogTypes logTypeId, string message) { using (HContext context = new HContext()) { Log log = new Log(); log.LogTypeId = logTypeId; log.Message = message; log.DateCreated = DateTime.Now; context.Logs.Add(log); context.SaveChanges(); } }