public static void Pop(ILoggingContext context) { var frameID = GetFrameID(context); var frame = new LoggingCallContextStackFrame(frameID); if (!frame.Deactivate()) { return; } using (var keySet = Keys().GetEditor()) { foreach (var key in frame.Keys) { var activeFrameData = new LoggingCallContextActiveFrameData(key); LoggingCallContextStackFrame currentFrame; while (activeFrameData.TryGetFrame(out currentFrame) && !currentFrame.IsActive()) { currentFrame.FreeKey(key); if (!activeFrameData.Pop()) { keySet.Remove(key); break; } } } CallContext.LogicalSetData(SERIALIZATION_KEY, SerializeToXML(keySet.DataStore())); } }
public override void Start() { ILoggingContext ctx = Kernel.Bind <ILoggingContext>() .To <Application1LoggingContext>().InThreadScope(); StartApplication(ctx, _enumerableWork); }
protected void Write( string @string, ILoggingContext context, string callerMemberName, int callerLineNumber, string callerFilePath) { if (_encoding != null) { var unicode = Encoding.Unicode; var bytes = unicode.GetBytes(@string); @string = _encoding.GetString(Encoding.Convert(unicode, _encoding, bytes)); } lock (_lock) { var stream = StreamCreator(_path); using (var writer = new StreamWriter(stream)) writer.Write(Formatter(@string, DateTime.Now) + Environment.NewLine + new string('-', 80) + Environment.NewLine); if (DisposeStream) { stream.Dispose(); } } }
public NLogLogger(Type loggerType = null, ILoggingContext context = null, IDictionary <string, object> properties = null) { _loggerType = loggerType?.ToString() ?? "DefaultLogger"; _context = context; _properties = properties; _version = GetVersion(loggerType); }
private async Task AuthorizeConnectionAsync(ILoggingContext context, CancellationToken cancellationToken) { async Task Operation(ILoggingContext context, CancellationToken cancellationToken) { await LoginAsync(fConfig.ClientId, fConfig.ClientSecret, context, cancellationToken); await SubscribeResourcesAsync(fConfig.SubscribedResources, context, cancellationToken); } var operationConfig = new RetryOperationConfig { RetryCount = null, RetryPolicy = new Operations.RetryPolicy(TimeSpan.FromSeconds(60), 2) }; using (fLogger.TrackRequest(context, "Authorizing SignalR connection.", out var requestContext)) { await new RetryOperation(Operation, operationConfig) .Catch <Unit, HttpRequestException>(fLogger) .Catch <Unit, WebSocketException>(fLogger) .Catch <Unit, HubException>(fLogger) .Catch <Unit, Exception>(fLogger, true) .OnSuccess(requestContext) .OnFail(requestContext) .OnFailRethrow() .ExecuteAsync(requestContext, cancellationToken); } }
public static VerifyAccountEmailContext New(UserDoc user, ClientDoc client, ILoggingContext context) { return(new VerifyAccountEmailContext( user.EmailToken !, user.Email, client, context)); }
public RequestDataExtractorFilter(IRequestContextProvider requestContextProvider, IRequestContentProvider requestContentProvider, ILoggingContext loggingContext) { _requestContextProvider = requestContextProvider; _requestContentProvider = requestContentProvider; _loggingContext = loggingContext; }
protected void StartApplication <T>(ILoggingContext ctx, IEnumerable <T> enumerableWork) { Parallel.ForEach(enumerableWork, iter => { // this code can refer to ctx e.g. ctx.Log(message); }); }
public void LogException( Exception exception, ILoggingContext context, string callerMemberName = null, int callerLineNumber = 0, string callerFilePath = null) { Write(exception.ToString(), context, callerMemberName, callerLineNumber, callerFilePath); }
public void LogString( string @string, ILoggingContext context, string callerMemberName = null, int callerLineNumber = 0, string callerFilePath = null) { Write(@string, context, callerMemberName, callerLineNumber, callerFilePath); }
public static PasswordResetEmailContext New(UserDoc user, ClientDoc client, ILoggingContext context) { return(new PasswordResetEmailContext( user.PasswordToken !, user.Id, user.Username, user.Email, client, context)); }
public PlatformTokenDistributer(IPlatformTokenProvider platformTokenProvider, IPlatformHashProvider platformHashProvider, IUsersApi usersApi, ILoggingContext loggingContext) { _platformTokenProvider = platformTokenProvider; _platformHashProvider = platformHashProvider; _usersApi = usersApi; _loggingContext = loggingContext; }
public LogInspectorEntry(LogInspectorLevel level, DateTime timeStamp, string loggerName, string message, Exception exception = null, ILoggingContext context = null) { Level = level; TimeStamp = timeStamp; LoggerName = loggerName; Message = message; Context = context; Exception = exception; }
public static bool TryGetContextData(ILoggingContext ctx, string key, out object result) { var frame = new LoggingCallContextStackFrame(GetFrameID(ctx)); if (!frame.IsActive()) { result = null; return(false); } return(frame.GetValue(key, out result)); }
public void LogString( string @string, ILoggingContext context, string callerMemberName = null, int callerLineNumber = 0, string callerFilePath = null) { lock (_lock) { foreach (var logger in Loggers) { logger.LogString(@string, context, callerMemberName, callerLineNumber, callerFilePath); } } }
public async Task <TokenConfigurationModel> GetAsync(Uri authorityUrl, ILoggingContext context, CancellationToken cancellationToken) { var url = authorityUrl.AppendPath("api/v1/token/configuration"); var client = HttpClientContext.Client; var result = await client.GetAsync(url, cancellationToken); result.EnsureSuccessStatusCode(); var body = await result.Content.ReadAsStringAsync(cancellationToken); var model = await JsonConvert.DeserializeAsync <TokenConfigurationModel>(body, JsonConvert.CammelCaseOptions, cancellationToken); Debug.Assert(model != null); return(model); }
public void LogException( Exception exception, ILoggingContext context, string callerMemberName = null, int callerLineNumber = 0, string callerFilePath = null) { lock (_lock) { foreach (var logger in Loggers) { logger.LogException(exception, context, callerMemberName, callerLineNumber, callerFilePath); } } }
public static bool TryGetContextData <T>(ILoggingContext ctx, string key, out T result) { object innerResult; var found = TryGetContextData(ctx, key, out innerResult); if (found) { result = (T)innerResult; return(true); } else { result = default(T); return(false); } }
public static LoggingCallContextStackFrame Initialize(ILoggingContext context, IEnumerable <KeyValuePair <string, object> > data) { string FrameID = LoggingCallContextStore.GetFrameID(context); var valueStore = ValueStore(FrameID); List <string> keys = new List <string>(); foreach (var pair in data) { keys.Add(pair.Key); valueStore.AddOrUpdate(pair.Key, () => pair.Value, (o) => pair.Value); } ActiveFramesMap().AddOrUpdate(FrameID, () => "active", (o) => "active"); KeysStore().AddOrUpdate(FrameID, () => keys, (o) => keys); return(new LoggingCallContextStackFrame(FrameID)); }
public LogScope( IEnumerable <ILogStream> streams, ILogToken lt, List <KeyValuePair <string, object> > contextData) { foreach (var log in streams) { // provide loggers chance to attach data if needed log.OnAttachScopeParameters(lt, contextData); } // push context data _context = LoggingCallContextStore.Push(contextData); _streams = streams; _lt = lt; _contextData = contextData; }
public void LogString(string @string, ILoggingContext context, string callerMemberName = null, int callerLineNumber = 0, string callerFilePath = null) { var lockTaken = false; try { _lock.Enter(ref lockTaken); Writer(@string); } finally { if (lockTaken) { _lock.Exit(); } } }
public static void ChangeContext(this EventBase message, ILoggingContext context) { if (message is null) { throw new ArgumentNullException(nameof(message)); } if (context is null) { throw new ArgumentNullException(nameof(context)); } if (context.ScopeId != message.ScopeId) { throw new ArgumentException("Unable to change contex, because it has different correlation id than message.", nameof(context)); } message.ParentScopeId = context.ParentScopeId; }
/// <summary> /// Sets up the data context and UserPermissionService for the service and all services injected in the service /// </summary> /// <param name="dataContext">data context</param> /// <param name="userPermissionService">UserPermissionService</param> public void SetupService(DataContext dataContext, ILoggingContext loggingDb, UserPermissionService userPermissionService) { db = dataContext; LoggingDb = loggingDb; UserPermissionService = userPermissionService; // go through all fields, if any of them are a BaseService Setup DB and UPS BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance | BindingFlags.DeclaredOnly; var fields = this.GetType().UnderlyingSystemType.GetFields(flags).Where(w => w.FieldType.BaseType == typeof(BaseService)).ToList(); foreach (var item in fields) { var baseService = (item.GetValue(this) as BaseService); baseService?.SetupService(db, LoggingDb, UserPermissionService); } }
public void LogException(Exception exception, ILoggingContext context, string callerMemberName = null, int callerLineNumber = 0, string callerFilePath = null) { var lockTaken = false; try { _lock.Enter(ref lockTaken); Writer(exception.ToString()); } finally { if (lockTaken) { _lock.Exit(); } } }
private async Task LoginAsync(string clientId, string clientSecret, ILoggingContext context, CancellationToken cancellationToken) { using (fLogger.TrackRequest(context, "Authority Hub Login.", out var requestContext)) { try { var request = new LoginRequest(clientId, clientSecret, requestContext); const string method = nameof(IRemoteServer.LoginAsync); await fState.Connection.InvokeAsync <LoginResponse>(method, request, cancellationToken); requestContext.Success(); } catch { requestContext.Fail(); throw; } } }
private async Task SubscribeResourcesAsync(string[] resources, ILoggingContext context, CancellationToken cancellationToken) { using (fLogger.TrackRequest(context, "Authority Hub Subscribe resources.", out var requestContext)) { try { var request = new SubscribeEventsRequest(resources, requestContext); const string method = nameof(IRemoteServer.SubscribeResourceAsync); await fState.Connection.InvokeAsync <SubscribeEventsResponse>(method, request, cancellationToken); requestContext.Success(); } catch { requestContext.Fail(); throw; } } }
private static string GetCorrelationContext(HttpClient http, ILoggingContext context) { UnsafeStringBuilder correlationContextBuilder = null; var propertyNames = new HashSet <string>(); try { context.ForEachProperty((LoggingProperty property, object value, ref object _) => { if (!property.IsBaggage || !propertyNames.Add(property.Name)) { return; } if (correlationContextBuilder == null) { propertyNames = new HashSet <string>(); correlationContextBuilder = new UnsafeStringBuilder(1024); } if (correlationContextBuilder.Length > 0) { correlationContextBuilder.Append(", "); } correlationContextBuilder.Append(property.Name); correlationContextBuilder.Append('='); var formatter = property.Formatter ?? LoggingServices.Formatters.Get(value.GetType()); formatter.Write(correlationContextBuilder, value); }); return(correlationContextBuilder?.ToString()); } finally { correlationContextBuilder?.Dispose(); } }
protected void Write(string @string, ILoggingContext context, string callerMemberName, int callerLineNumber, string callerFilePath) { byte[] log; if (_encoding == null) { log = Encoding.Unicode.GetBytes(@string); } else { var unicode = Encoding.Unicode; var bytes = unicode.GetBytes(@string); log = Encoding.Convert(unicode, _encoding, bytes); } lock (_lock) { _writer.Write(log); } }
protected EventBase(ILoggingContext context) { ScopeId = context.ScopeId; ParentScopeId = context.ParentScopeId; }
public SubscribeEventsResponse(ILoggingContext context) : base(context) { }