本文整理汇总了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));
}
示例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;
}
示例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;
}
示例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();
}
}
示例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");
}
示例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;
}
}
示例7: WriteInnerException
private static void WriteInnerException(StringBuilder sb, Exception inner)
{
if (inner == null)
return;
sb.AppendLine(" InnerException: ------------------------------------------------");
sb.AppendLine(inner.ToLogString());
sb.AppendLine(" EndInnerException: ---------------------------------------------");
}