当前位置: 首页>>代码示例>>C#>>正文


C# Exception.ToLogString方法代码示例

本文整理汇总了C#中System.Exception.ToLogString方法的典型用法代码示例。如果您正苦于以下问题:C# Exception.ToLogString方法的具体用法?C# Exception.ToLogString怎么用?C# Exception.ToLogString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Exception的用法示例。


在下文中一共展示了Exception.ToLogString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldWrite

        public void ShouldWrite()
        {
            var inner1Ex = new NullReferenceException("inner1Message");
            var inner2Ex = new InvalidOperationException("inner2Message", inner1Ex);
            var outerEx = new Exception("outerMessage", inner2Ex);

            var expectedOutput = @"----------
            outerMessage
            ----------
            Debug information:
            ----------
            Exception: outerMessage
            [StackTrace:Exception]
            ----------
            inner InvalidOperationException: inner2Message
            [StackTrace:InvalidOperationException]
            ----------
            inner NullReferenceException: inner1Message
            [StackTrace:NullReferenceException]
            ----------
            ";

            Func<Exception, string> stackTraceFormatter = ex => string.Format("[StackTrace:{0}]", ex.GetType().Name);

            var actual = outerEx.ToLogString(stackTraceFormatter);

            Assert.That(expectedOutput, Is.EqualTo(actual));
        }
开发者ID:endjin,项目名称:DeployToAzure,代码行数:28,代码来源:ExceptionExtensionsTests.cs

示例2: NewDbModelChangeScript

 public static IDbUpgradeScript NewDbModelChangeScript(this IDbUpgradeBatch batch, 
     DbObjectChangeType changeType,  DbObjectType objectType,
     string fullObjectName,
     string sql, int executionOrder, int subOrder, int duration, Exception exception)
 {
     var session = EntityHelper.GetSession(batch);
       var ent = session.NewEntity<IDbUpgradeScript>();
       ent.Batch = batch;
       ent.ObjectType = objectType;
       ent.FullObjectName = fullObjectName;
       ent.ExecutionOrder = executionOrder;
       ent.SubOrder = subOrder;
       ent.Sql = sql;
       ent.Duration = duration;
       if(exception != null)
     ent.Errors = exception.ToLogString();
       return ent;
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:18,代码来源:DbUpgradeLogExtensions.cs

示例3: NewDbModelChangeBatch

 public static IDbUpgradeBatch NewDbModelChangeBatch(this IEntitySession session,
     string fromVersion, string toVersion, DateTime startedOn, DateTime? completedOn,
     DbUpgradeMethod method, string machineName, string userName,
     Exception exception = null)
 {
     var ent = session.NewEntity<IDbUpgradeBatch>();
       ent.FromVersion = fromVersion;
       ent.ToVersion = toVersion;
       ent.StartedOn = startedOn;
       ent.CompletedOn = completedOn;
       ent.Method =  method;
       ent.MachineName = machineName ?? Environment.MachineName;
       ent.UserName = userName ?? Environment.UserName;
       if (exception == null)
     ent.Success = true;
       else {
     ent.Success = false;
     ent.Errors = exception.ToLogString();
       }
       return ent;
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:21,代码来源:DbUpgradeLogExtensions.cs

示例4: LogError

 public Guid LogError(Exception exception, OperationContext context = null)
 {
     if(!this.App.IsConnected()) {
     OnErrorLogged(context, exception);
     Util.WriteToTrace(exception, context.GetLogContents(), copyToEventLog: true);
     return Guid.Empty;
       }
       try {
     var session = this.App.OpenSystemSession();
     session.DisableStoredProcs(); //as a precaution, taking simpler path, in case something wrong with stored procs
     var errInfo = session.NewEntity<IErrorLog>();
     errInfo.CreatedOn = App.TimeService.UtcNow;
     errInfo.LocalTime = App.TimeService.Now;
     errInfo.Message = Util.CheckLength(exception.Message, 250);
     errInfo.Details = exception.ToLogString(); //writes exc.ToString() and exc.Data collection, along with all inner exception details
     errInfo.ExceptionType = exception.GetType().Name;
     errInfo.MachineName = Environment.MachineName;
     if(context != null) {
       errInfo.AppName = context.App.AppName;
       errInfo.OperationLog = context.GetLogContents();
       errInfo.UserName = context.User.UserName;
       if(context.UserSession != null)
     errInfo.UserSessionId = context.UserSession.SessionId;
       if (context.WebContext != null)
     errInfo.WebCallId = context.WebContext.Id;
     }
     session.SaveChanges();
     OnErrorLogged(context, exception);
     return errInfo.Id;
       } catch (Exception logEx) {
     Util.WriteToTrace(logEx, "Fatal failure in database error log. See next error log entry for original error.");
     Util.WriteToTrace(exception, null, copyToEventLog: true);
     return Guid.NewGuid();
       }
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:35,代码来源:ErrorLogModule.cs

示例5: WriteException

 private static void WriteException(Exception ex)
 {
     var err = ex.ToLogString();
       Console.ForegroundColor = ConsoleColor.Red;
       Console.WriteLine();
       Console.WriteLine("Exception: ");
       Console.WriteLine(err);
       Console.ResetColor();
       LogError(err + "\r\n");
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:10,代码来源:Program.cs

示例6: UpdateDbInfo

 public bool UpdateDbInfo(Database db, Exception exception = null)
 {
     //Check that db has module's tables; if not, this module is not included in the solution
       var tbl = db.DbModel.GetTable(typeof(IDbInfo));
       if (tbl == null)
     return false;
       try {
     var app = db.DbModel.EntityApp;
     var session = App.OpenSystemSession();
     // Disable stored procs and disable batch mode
     session.DisableStoredProcs();
     session.DisableBatchMode();
     var ent = session.GetEntities<IDbInfo>(take: 1).FirstOrDefault(e => e.AppName == app.AppName);
     if(ent == null) {
       ent = session.NewEntity<IDbInfo>();
       ent.Version = app.Version.ToString();
       ent.AppName = app.AppName;
     }
     if(exception == null) {
       ent.Version = app.Version.ToString();
       ent.LastModelUpdateFailed = false;
       ent.LastModelUpdateError = null;
       ent.Values = SerializeValues(db.DbModel.VersionInfo);
       SaveModulesInfo(session, db.DbModel.VersionInfo);
     } else {
       ent.LastModelUpdateFailed = true;
       ent.LastModelUpdateError = exception.ToLogString();
     }
     // we use db.SaveChanges directly, to make sure we go thru proper database
     var entSession = (Vita.Entities.Runtime.EntitySession)session;
     db.SaveChanges(entSession);
     return true;
       } catch (Exception ex) {
     App.ActivationLog.Error(ex.ToLogString());
     return false;
       }
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:37,代码来源:DbInfoModule.cs

示例7: WriteInnerException

 private static void WriteInnerException(StringBuilder sb, Exception inner)
 {
     if (inner == null)
     return;
       sb.AppendLine("   InnerException: ------------------------------------------------");
       sb.AppendLine(inner.ToLogString());
       sb.AppendLine("   EndInnerException: ---------------------------------------------");
 }
开发者ID:yuanfei05,项目名称:vita,代码行数:8,代码来源:LoggingExtensions.cs


注:本文中的System.Exception.ToLogString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。