public async Task <IActionResult> CallRest <D, T, G, A>(Func <T, G, A, Task <OperationResult <D> > > result, T input, G input1, A input2) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { OperationResult <D> res = await result(input, input1, input2); if (res.Succeeded) { return(Ok(res.SuccessResult)); } return(BadRequest(res.Errors)); } catch (Exception e) { Loki.ExceptionError(e); HttpContext.Items["Exception"] = e; if (RethrowException) { throw; } return(BadRequest(OperationResult.Fail <D>(GeneralErrorCode, GeneralErrorMessage).Errors)); } }
public IActionResult CallRest <D, T>(Func <T, OperationResult <D> > result, T input) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { OperationResult <D> res = result(input); if (res.Succeeded) { return(Ok(res.SuccessResult)); } return(BadRequest(res.Errors)); } catch (Exception e) { Loki.ExceptionError(e); HttpContext.Items["Exception"] = e; if (RethrowException) { throw; } return(BadRequest(OperationResult.Fail <D>(GeneralErrorCode, GeneralErrorMessage).Errors)); } }
public IActionResult CallRest <D, T, G, A, B, C, E, F, H, I, J>(Func <T, G, A, B, C, E, F, H, I, J, OperationResult <D> > result, T input, G input1, A input2, B input3, C input4, E input5, F input6, H input7, I input8, J input9) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { OperationResult <D> res = result(input, input1, input2, input3, input4, input5, input6, input7, input8, input9); if (res.Succeeded) { return(Ok(res.SuccessResult)); } return(BadRequest(res.Errors)); } catch (Exception e) { Loki.ExceptionError(e); HttpContext.Items["Exception"] = e; if (RethrowException) { throw; } return(BadRequest(OperationResult.Fail <D>(GeneralErrorCode, GeneralErrorMessage).Errors)); } }
public async Task Invoke(HttpContext context) { WebRestLog log = new WebRestLog() { TraceId = context.TraceIdentifier }; try { log = await LogRequest(context.Request, log); } catch (Exception e) { Loki.ExceptionWarning("Error in Loki Middleware logging Request", e); } var originalBodyStream = context.Response.Body; using (var responseBody = new MemoryStream()) { context.Response.Body = responseBody; await _next(context); await LogResponse(context.Response, log); await responseBody.CopyToAsync(originalBodyStream); } }
public void Init(object instance, MethodBase method, object[] args) { _stopwatch = new Stopwatch(); _methodName = method.Name; _className = method.DeclaringType.FullName; Loki.Write(Loki.INVOKE_TYP, LogLevel.SystemGenerated, null, _methodName, _className, -1, args); }
static void Main(string[] args) { Loki loki = new Loki(); // Install assistant loki.Install(); // Start him loki.Start(); }
void Awake() { if (S == null) { S = this; } else { } }
void Awake() { if (S == null) { S = this; } else { Debug.LogError("Hero.Awake() - attapted to assign second Hero.S!"); } }
public async Task <IActionResult> CallRest <D>(Func <Task <OperationResult <D> > > result) { try { OperationResult <D> res = await result(); if (res.Succeeded) { return(Ok(res.SuccessResult)); } return(BadRequest(res.Errors)); } catch (Exception e) { Loki.ExceptionError(e); HttpContext.Items["Exception"] = e; if (RethrowException) { throw; } return(BadRequest(OperationResult.Fail <D>(GeneralErrorCode, GeneralErrorMessage).Errors)); } }
public LokiObjectAdapter() { _logs = new ConcurrentQueue <Log>(); _client = new HttpClient(); Loki.UpdateAdapter(this); }
public async Task Invoke(HttpContext context) { if (!LokiObjectAdapter.LokiConfig.UseLokiMiddleware || LokiObjectAdapter.LokiConfig.IgnoreRoutes.Any(x => context.Request.Path.ToString().Contains(x))) { await _next(context); } else { WebRestLog log = new WebRestLog() { TraceId = context.TraceIdentifier }; try { if (!LokiObjectAdapter.LokiConfig.NoRequestRoutes.Any(x => context.Request.Path.ToString().Contains(x))) { log = await LogRequest(context.Request, log); } } catch (Exception e) { Loki.ExceptionWarning("Error in Loki Middleware logging Request", e); } var originalBodyStream = context.Response.Body; //Create a new memory stream... using (var responseBody = new MemoryStream()) { context.Response.Body = responseBody; try { await _next(context); if (context.Items.ContainsKey("Exception")) { Exception ex = (Exception)context.Items["Exception"]; log.Exception = ex.Message + "\n" + ex.StackTrace + "\n" + ex.Source; } } catch (Exception e) { log.Exception = e.Message + "\n" + e.StackTrace + "\n" + e.Source; await LogResponse(context.Response, log); Loki.Write(Loki.REST_TYP, LogLevel.Error, "", "Invoke", "LokiWebExtension.Middleware.LokiMiddleware", 48, log); throw; } try { if (!LokiObjectAdapter.LokiConfig.NoResponseRoutes.Any(x => context.Request.Path.ToString().Contains(x))) { await LogResponse(context.Response, log); } } catch (Exception e) { Loki.ExceptionWarning("Error in Loki Middleware logging Response", e); } if (originalBodyStream.CanWrite && responseBody.CanRead) { await responseBody.CopyToAsync(originalBodyStream); } } Loki.Write(Loki.REST_TYP, LogLevel.SystemGenerated, "", "Invoke", "LokiWebExtension.Middleware.LokiMiddleware", 55, log); } }
public void OnException(Exception exception) { _stopwatch.Stop(); Loki.Write(Loki.EXCEPTION_TYP, LogLevel.SystemGenerated, null, _methodName, _className, -1, exception); }
public void OnExit() { _stopwatch.Stop(); Loki.Write(Loki.RETURN_TYP, LogLevel.SystemGenerated, null, _methodName, _className, -1, _stopwatch.ElapsedTicks); }