c# - Owin Call Duration -
is there simple way find call duration in c#.
i using owin middleware intercept calls api , log information them , part of log duration of call.
public override async task invoke(iowincontext context) { var request = context.request; var response = context.response; var username = request.user != null && request.user.identity.isauthenticated ? request.user.identity.name : "no username"; var entity = new trackingentity() { username = username }; // invoke next middleware in pipeline await next.invoke(context); writerequestheaders(request, entity); writeresponseheaders(response, entity); await storage.insertentity(entity); }
if tracking entity has duration field on storing time length of call best way go recording it?
public timespan duration { get; set; }
is accurate way use timer starts before calling next , ends after?
any input appreciated think i'm overthinking this.
thanks in advance.
i don't think need overhead of creating timer, record start time variable , end time in variable set duration.
var starttime = datetime.now; await next.invoke(context); var endtime = datetime.now; duration = endtime - starttime;
it's little messy, if doing in middleware logging, want quick, , should fit bill.
Comments
Post a Comment