本文整理汇总了C#中System.Web.Http.ExceptionHandling.ExceptionLoggerContext类的典型用法代码示例。如果您正苦于以下问题:C# ExceptionLoggerContext类的具体用法?C# ExceptionLoggerContext怎么用?C# ExceptionLoggerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ExceptionLoggerContext类属于System.Web.Http.ExceptionHandling命名空间,在下文中一共展示了ExceptionLoggerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Log
public override void Log(ExceptionLoggerContext context)
{
if (context != null && context.Exception != null && context.Request != null)
{
string excToString = context.Exception.ToString();
var entityValidationExc = context.Exception as System.Data.Entity.Validation.DbEntityValidationException;
if (entityValidationExc != null)
excToString += Environment.NewLine
+ string.Join(Environment.NewLine, entityValidationExc.EntityValidationErrors.SelectMany(p => p.ValidationErrors.Select(q => q.PropertyName + ": " + q.ErrorMessage)));
var usedController = ((System.Web.Http.ApiController)context.ExceptionContext.ControllerContext.Controller);
//similar to Global.asax/CustomLogRequest
//todo: missing user and IP, catch Exceptions and null reference
Trace.TraceError("CustomExceptionLogger"
+ Environment.NewLine
+ "HTTP {0} {1}"
+ Environment.NewLine
+ "Form Keys: {2}"
+ Environment.NewLine,
//+ "User: {3}, IP: {4}",
context.Request.Method.Method, context.Request.RequestUri,
string.Join(Environment.NewLine,
usedController.ActionContext.ActionArguments.Select(p => p.Key + ": " + JsonConvert.SerializeObject(p.Value))));
//username, ip);
}
}
示例2: Log
public override void Log(ExceptionLoggerContext context)
{
if (context != null)
{
Trace.TraceError(context.ExceptionContext.Exception.ToString());
}
}
示例3: LogAsync
public Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken)
{
var logger = context.Request.GetAutofacScope().Resolve<ILogger>();
logger.ErrorFormat("Unhandled exception: {0}", context.Exception);
return Task.FromResult<object>(null);
}
示例4: Log
public override void Log(ExceptionLoggerContext context)
{
#if DEBUG
Debug.WriteLine("Logging");
#endif
logger.Log(LogLevel.Trace, context.Exception);
}
示例5: Log
public override void Log(ExceptionLoggerContext context) {
var contextData = new ContextData();
contextData.MarkAsUnhandledError();
contextData.SetSubmissionMethod("ExceptionLogger");
contextData.Add("HttpActionContext", context.ExceptionContext.ActionContext);
context.Exception.ToExceptionless(contextData).Submit();
}
示例6: Log
public override void Log(ExceptionLoggerContext context)
{
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data");
path = Path.Combine(path, "UserAdminException.txt");
Directory.CreateDirectory(path);
var msg = DateTime.Now.ToString() + Environment.NewLine + context.Exception.ToString() + Environment.NewLine + Environment.NewLine;
File.AppendAllText(path, msg);
}
示例7: LogAsync
public Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken)
{
string requestDescription = context.Request.GetDescription();
logger.WriteCritical($"Exception while processing {requestDescription}.", context.Exception);
return Task.FromResult(true);
}
示例8: Log
public void Log(Exception ex, HttpRequestMessage request, string catchBlockName)
{
var catchBlock = new ExceptionContextCatchBlock(catchBlockName, true, false);
var exceptionContext = new ExceptionContext(ex, catchBlock, request);
var exceptionLoggerContext = new ExceptionLoggerContext(exceptionContext);
Log(exceptionLoggerContext);
}
示例9: Log
public override void Log(ExceptionLoggerContext context)
{
using (var log = Logger.GetLogger(this))
{
string errorMessage = $"Unhandled exception processing {context.Request.Method} for {context.Request.RequestUri}: {context.Exception}";
log.Error(errorMessage);
}
}
示例10: LogAsync
public async Task LogAsync(ExceptionLoggerContext context, CancellationToken cancellationToken)
{
Logger.ErrorException("Unhandled exception", context.Exception);
var env = context.Request.GetOwinEnvironment();
var events = env.ResolveDependency<IEventService>();
await events.RaiseUnhandledExceptionEventAsync(context.Exception);
}
示例11: Log
public override void Log(ExceptionLoggerContext context) {
_logger.Error()
.Exception(context.Exception)
.SetActionContext(context.ExceptionContext.ActionContext)
.MarkUnhandled("ExceptionLogger")
.Message("Unhandled: {0}", context.Exception.Message)
.Write();
}
示例12: Log
public override void Log(ExceptionLoggerContext context)
{
if (context?.Exception != null)
{
_AiClient.TrackException(context.Exception);
}
base.Log(context);
}
示例13: ShouldLogAsError
private bool ShouldLogAsError(ExceptionLoggerContext context)
{
return (!(context.Exception is MdmFaultException) &&
!(context.Exception is NotFoundException) &&
!(context.Exception is ValidationException) &&
!(context.Exception is NotImplementedException) &&
!(context.Exception is VersionConflictException)
);
}
示例14: Log
public override void Log(ExceptionLoggerContext context)
{
var shouldBeWarning = Extension.IsType(context.Exception, new List<Type> { typeof(ValidationException), typeof(BaseLogicException<>) });
if (shouldBeWarning)
Logger.Warn(context.Exception.GetType().Name, context.Exception);
else
Logger.Error("An unhandled exception has occured", context.Exception);
}
示例15: Log
public override void Log(ExceptionLoggerContext context)
{
var logger = context.Request.GetDependencyScope().GetService(typeof(ILogger)) as ILogger;
if (logger != null && context.Exception != null)
{
logger.Log(context.Exception.Message);
}
}