Skip to content

Instantly share code, notes, and snippets.

@michael-newton-15below
Created January 14, 2013 21:11
Show Gist options
  • Save michael-newton-15below/4533554 to your computer and use it in GitHub Desktop.
Save michael-newton-15below/4533554 to your computer and use it in GitHub Desktop.
AuditBuilder
module FifteenBelow.MailWatcher.ErrorHandling.Audit
open ...
type AuditBuilder (auditClient : IAuditClient, log : ILog, config : IConfigurationManager) =
let app = config.ApplicationInformation
member this.Bind (expr, func) =
match expr with
| None -> None
| Some r ->
try func r
with
| _ as e ->
auditClient.Log(AuditReport
(
ReportType = EnumTypes.AuditTypes.ERROR_REPORT,
Message = e.Message,
FunctionName = e.TargetSite.Name,
LogLevel = EnumTypes.log4netLevels.ERROR,
SourceApplication = app.ApplicationShortName,
ReportCode = 0,
Occurrence = System.DateTime.Now,
SourceServer = System.Environment.GetEnvironmentVariable("COMPUTERNAME")
))
log.Error(e.Message, e)
None
member this.Delay (f: unit -> _) =
f ()
member this.Return (value) =
Some value
member this.ReturnFrom (value) =
value
member this.TryFinally (expr, comp) =
try this.ReturnFrom(expr)
finally comp ()
member this.Using (res : #System.IDisposable, expr) =
this.TryFinally(expr res, fun () -> res.Dispose())
interface IErrorHandlerBuilder with
member this.Bind (expr, func) = this.Bind (expr, func)
member this.Delay (f) = this.Delay (f)
member this.Return (value) = this.Return (value)
member this.ReturnFrom (value) = this.ReturnFrom(value)
member this.TryFinally (expr, comp) = this.TryFinally (expr, comp)
member this.Using (res : #System.IDisposable, expr) = this.Using (res, expr)
member this.Zero () = None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment