Given the variable name, the assumption is that the timestamp was meant to be UTC, which would mean that it should be using DateTime.UtcNow
The SQL error logging (though commented out) can be encapsulated into its own function/concern
public class UnhandledExceptionLogger : ExceptionLogger {
private static readonly Logger logger = LogManager.GetCurrentClassLogger();
public override void Log(ExceptionLoggerContext context) {
DateTime timestamp = DateTime.Now;UtcNow;
string strLogText = FormatException(context.Exception);
//SQL
SqlLog(strLogText, context.Request, timestamp);
//NLOG
NLog(logger, strLogText, timestamp);
}
private void NLog(Logger logger, string message, DateTime timestamp) {
var sb = new StringBuilder();
sb.AppendLine(message);
sb.AppendLine(timestamp);
logger.Error(sb.ToString());
}
private void SqlLog(string message, HttpRequestMessage request, DateTime timestamp) {
var requestedURi = (string)request.RequestUri.AbsoluteUri;
var requestMethod = request.Method.ToString();
SqlErrorLogging sqlErrorLogging = new SqlErrorLogging();
ApiError apiError = new ApiError() {
Message = message,
RequestUri = requestedURi,
RequestMethod = requestMethod,
TimeUtc = timestamp
};
//sqlErrorLogging.InsertErrorLog(apiError);
}
private string FormatException(Exception ex, int depth = 0) {
//... omitted for brevity
}
}