本文整理汇总了C#中IRequest.GetItemOrCookie方法的典型用法代码示例。如果您正苦于以下问题:C# IRequest.GetItemOrCookie方法的具体用法?C# IRequest.GetItemOrCookie怎么用?C# IRequest.GetItemOrCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRequest
的用法示例。
在下文中一共展示了IRequest.GetItemOrCookie方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Log
public void Log(IRequest request, object requestDto, object response, TimeSpan requestDuration)
{
var requestType = requestDto != null ? requestDto.GetType() : null;
if (ExcludeRequestDtoTypes != null
&& requestType != null
&& ExcludeRequestDtoTypes.Contains(requestType))
return;
var entry = new RequestLogEntry {
Id = Interlocked.Increment(ref requestId),
DateTime = DateTime.UtcNow,
RequestDuration = requestDuration,
};
if (request != null)
{
entry.HttpMethod = request.Verb;
entry.AbsoluteUri = request.AbsoluteUri;
entry.PathInfo = request.PathInfo;
entry.IpAddress = request.UserHostAddress;
entry.ForwardedFor = request.Headers[HttpHeaders.XForwardedFor];
entry.Referer = request.Headers[HttpHeaders.Referer];
entry.Headers = request.Headers.ToDictionary();
entry.UserAuthId = request.GetItemOrCookie(HttpHeaders.XUserAuthId);
entry.SessionId = request.GetSessionId();
entry.Items = SerializableItems(request.Items);
entry.Session = EnableSessionTracking ? request.GetSession() : null;
}
if (HideRequestBodyForRequestDtoTypes != null
&& requestType != null
&& !HideRequestBodyForRequestDtoTypes.Contains(requestType))
{
entry.RequestDto = requestDto;
if (request != null)
{
entry.FormData = request.FormData.ToDictionary();
if (EnableRequestBodyTracking)
{
entry.RequestBody = request.GetRawBody();
}
}
}
if (!response.IsErrorResponse()) {
if (EnableResponseTracking)
entry.ResponseDto = response;
}
else {
if (EnableErrorTracking)
entry.ErrorResponse = ToSerializableErrorResponse(response);
}
logEntries.Enqueue(entry);
RequestLogEntry dummy;
if (logEntries.Count > capacity)
logEntries.TryDequeue(out dummy);
}
示例2: CreateEntry
protected RequestLogEntry CreateEntry(IRequest request, object requestDto, object response, TimeSpan requestDuration, Type requestType)
{
var entry = new RequestLogEntry
{
Id = Interlocked.Increment(ref requestId),
DateTime = DateTime.UtcNow,
RequestDuration = requestDuration,
};
if (request != null)
{
entry.HttpMethod = request.Verb;
entry.AbsoluteUri = request.AbsoluteUri;
entry.PathInfo = request.PathInfo;
entry.IpAddress = request.UserHostAddress;
entry.ForwardedFor = request.Headers[HttpHeaders.XForwardedFor];
entry.Referer = request.Headers[HttpHeaders.Referer];
entry.Headers = request.Headers.ToDictionary();
entry.UserAuthId = request.GetItemOrCookie(HttpHeaders.XUserAuthId);
entry.SessionId = request.GetSessionId();
entry.Items = SerializableItems(request.Items);
entry.Session = EnableSessionTracking ? request.GetSession() : null;
new NameValueCollection().ToDictionary();
}
if (HideRequestBodyForRequestDtoTypes != null
&& requestType != null
&& !HideRequestBodyForRequestDtoTypes.Contains(requestType))
{
entry.RequestDto = requestDto;
if (request != null)
{
entry.FormData = request.FormData.ToDictionary();
if (EnableRequestBodyTracking)
{
entry.RequestBody = request.GetRawBody();
}
}
}
if (!response.IsErrorResponse())
{
if (EnableResponseTracking)
entry.ResponseDto = response;
}
else
{
if (EnableErrorTracking)
entry.ErrorResponse = ToSerializableErrorResponse(response);
}
return entry;
}
示例3: CreateEntry
protected SeqRequestLogEntry CreateEntry(
IRequest request,
object requestDto,
object response,
TimeSpan requestDuration,
Type requestType)
{
var requestLogEntry = new SeqRequestLogEntry();
requestLogEntry.Timestamp = DateTime.UtcNow.ToString("o");
requestLogEntry.MessageTemplate = "HTTP {HttpMethod} {PathInfo} responded {StatusCode} in {ElapsedMilliseconds}ms";
requestLogEntry.Properties.Add("IsRequestLog", "True"); // Used for filtering requests easily
requestLogEntry.Properties.Add("SourceContext", "ServiceStack.Seq.RequestLogsFeature");
requestLogEntry.Properties.Add("ElapsedMilliseconds", requestDuration.TotalMilliseconds);
requestLogEntry.Properties.Add("RequestCount", Interlocked.Increment(ref requestId).ToString());
requestLogEntry.Properties.Add("ServiceName", HostContext.AppHost.ServiceName);
if (request != null)
{
requestLogEntry.Properties.Add("HttpMethod", request.Verb);
requestLogEntry.Properties.Add("AbsoluteUri", request.AbsoluteUri);
requestLogEntry.Properties.Add("PathInfo", request.PathInfo);
requestLogEntry.Properties.Add("IpAddress", request.UserHostAddress);
requestLogEntry.Properties.Add("ForwardedFor", request.Headers[HttpHeaders.XForwardedFor]);
requestLogEntry.Properties.Add("Referer", request.Headers[HttpHeaders.Referer]);
requestLogEntry.Properties.Add("Session", EnableSessionTracking ? request.GetSession(false) : null);
requestLogEntry.Properties.Add("Items", request.Items.WithoutDuplicates());
requestLogEntry.Properties.Add("StatusCode", request.Response?.StatusCode);
requestLogEntry.Properties.Add("StatusDescription", request.Response?.StatusDescription);
requestLogEntry.Properties.Add("ResponseStatus", request.Response?.GetResponseStatus());
}
var isClosed = request.Response.IsClosed;
if (!isClosed)
{
requestLogEntry.Properties.Add("UserAuthId", request.GetItemOrCookie(HttpHeaders.XUserAuthId));
requestLogEntry.Properties.Add("SessionId", request.GetSessionId());
}
if (HideRequestBodyForRequestDtoTypes != null
&& requestType != null
&& !HideRequestBodyForRequestDtoTypes.Contains(requestType))
{
requestLogEntry.Properties.Add("RequestDto", requestDto);
if (request != null)
{
if (!isClosed)
{
requestLogEntry.Properties.Add("FormData", request.FormData.ToDictionary());
}
if (EnableRequestBodyTracking)
{
requestLogEntry.Properties.Add("RequestBody", request.GetRawBody());
}
}
}
if (!response.IsErrorResponse())
{
if (EnableResponseTracking)
{
requestLogEntry.Properties.Add("ResponseDto", response);
}
}
else if (EnableErrorTracking)
{
var errorResponse = response as IHttpError;
if (errorResponse != null)
{
requestLogEntry.Level = errorResponse.StatusCode >= HttpStatusCode.BadRequest
&& errorResponse.StatusCode < HttpStatusCode.InternalServerError
? "Warning"
: "Error";
requestLogEntry.Properties["StatusCode"] = (int)errorResponse.StatusCode;
requestLogEntry.Properties.Add("ErrorCode", errorResponse.ErrorCode);
requestLogEntry.Properties.Add("ErrorMessage", errorResponse.Message);
requestLogEntry.Properties.Add("StackTrace", errorResponse.StackTrace);
}
var ex = response as Exception;
if(ex != null)
requestLogEntry.Exception = ex.ToString();
}
if (AppendProperties != null)
{
foreach (var kvPair in AppendProperties?.Invoke(request, requestDto, response, requestDuration).Safe())
{
requestLogEntry.Properties.GetOrAdd(kvPair.Key, key => kvPair.Value);
}
}
foreach (var header in request.Headers.ToDictionary())
{
if (!requestLogEntry.Properties.ContainsValue(header.Value))
{
requestLogEntry.Properties.Add($"Header-{header.Key}", header.Value);
}
}
//.........这里部分代码省略.........