本文整理汇总了C#中OperationContext.GetLogContents方法的典型用法代码示例。如果您正苦于以下问题:C# OperationContext.GetLogContents方法的具体用法?C# OperationContext.GetLogContents怎么用?C# OperationContext.GetLogContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OperationContext
的用法示例。
在下文中一共展示了OperationContext.GetLogContents方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LogClientError
public Guid LogClientError(OperationContext context, Guid? id, string message, string details, string appName, DateTime? localTime = null)
{
try {
var session = context.OpenSystemSession();
IErrorLog errInfo;
Guid idValue = id == null ? Guid.Empty : id.Value;
if (idValue != Guid.Empty) {
//Check for duplicates
errInfo = session.GetEntity<IErrorLog>(idValue);
if (errInfo != null)
return idValue;
}
errInfo = session.NewEntity<IErrorLog>();
if(idValue != Guid.Empty)
errInfo.Id = idValue;
errInfo.ExceptionType = "ClientError";
//Some messages might be really long; check length to fit into the field; full message will still go into details column
errInfo.Message = Util.CheckLength(message, 250);
errInfo.Details = details;
errInfo.MachineName = Environment.MachineName;
errInfo.LocalTime = localTime != null ? localTime.Value : App.TimeService.Now;
errInfo.CreatedOn = App.TimeService.UtcNow;
errInfo.AppName = 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;
errInfo.IsClientError = true;
session.SaveChanges();
OnErrorLogged(context, new Exception("ClientError: " + message + Environment.NewLine + details));
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(message, details, null, copyToEventLog: true);
return Guid.NewGuid();
}
}
示例2: 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();
}
}
示例3: LogError
public Guid LogError(string message, string details, OperationContext context)
{
Util.WriteToTrace(message, details, context.GetLogContents());
OnErrorLogged(context, new Exception(message + Environment.NewLine + details));
return Guid.Empty;
}