public DelegateLogger(LogFunc log, string categoryName) { this.log = log; this.categoryName = categoryName; this.defaultScope = new LoggerScope(null, log, categoryName, this.scopes); }
public IDisposable BeginScope <TState>(TState state) { var scope = new LoggerScope(state, this.log, this.categoryName, this.scopes); this.scopes.Push(scope); return(scope); }
public PipelineContext(ServiceScope services, LoggerScope logs) { Assert.IsNotNull(services); Assert.IsNotNull(logs); Services = services; Logs = logs; }
public TestWorkspace(LoggerScope scope, ITemplateManager?templateManager = null, IOperationManager?operationManager = null, WorkspaceSettings?settings = null, Func <Task>?onInitialize = null, Func <Task>?onClear = null, Func <string, ITemplate?, Func <VariableCollection, ResolveContext, Task>, Task <IWorkItem?> >?onCreate = null, Func <IWorkItem?, IOperation, Func <VariableCollection, ResolveContext, Task>, OperationWatcher, ILogger, Task <PipelineResult <Wrapper <bool> > > >?onExecute = null) { Templates = templateManager ?? new InMemoryTemplateManager(); Operations = operationManager ?? new InMemoryOperationManager(); Settings = Task.FromResult(settings); OnCreate = onCreate; OnClear = onClear; OnInitialize = onInitialize; OnExecute = onExecute; LogScope = scope; }
protected virtual void Dispose(bool disposing) { if (!m_disposed) { if (disposing) { if (!m_resultLogged) { var endDateTime = DateTime.Now; var elapsedTime = endDateTime - StartDateTime; Logger.LogInformation($"End function ({elapsedTime.TotalMilliseconds} ms)"); } LoggerScope.Dispose(); } // TODO: free unmanaged resources (unmanaged objects) and override finalizer // TODO: set large fields to null m_disposed = true; } }
/// <summary> /// Accepts the new client connection. /// </summary> /// <param name="asyncResult">Handle of the asynchronous accept operation</param> private void EndAccept(IAsyncResult asyncResult) { var socket = (Socket)asyncResult.AsyncState; Socket clientSocket; try { clientSocket = socket.EndAccept(asyncResult); } catch (ObjectDisposedException) { // Listener socket was closed return; } // Listen for another connections right away socket.BeginAccept(EndAccept, socket); // Disable Nagle algorithm for control channel clientSocket.NoDelay = true; // Enable TCP keepalive for control channel if (keepAliveSettings != null) { clientSocket.IOControl(IOControlCode.KeepAliveValues, keepAliveSettings, null); } // Create logger scope for the connection var loggerScope = new LoggerScope(clientSocket.RemoteEndPoint, logger); loggerScope.WriteInfo(TraceResources.ClientConnected); // Create the server instance to handle all client communications serverFactory .Create(clientSocket, loggerScope) .Run(CancellationToken.None); }
public void Scope() { Logger logger = new Logger(); LoggerScope scope = logger.CreateScope("scope", LogLevel.Information); scope.Information("info"); scope.Debug("debug"); scope.Warning("warning"); scope.Error("error"); scope.Error(new Exception()); scope.Fatal("fatal"); scope.Fatal(new Exception()); LogItem item = logger.View().FirstOrDefault(); Assert.IsNotNull(item); Assert.AreEqual(LogLevel.Information, item.Level); Assert.AreEqual("/scope", item.Scope); StringAssert.Contains(item.Content, "info"); LoggerScope subScope = scope.CreateScope("subScope", LogLevel.Debug); Assert.AreEqual("/scope/subScope", subScope.Name); }
public static void Invoked(this LoggerScope scope, string content = "", [CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0) => scope.Log($"Invoked: {content}", LogLevel.Debug, memberName, sourceFilePath, sourceLineNumber);
public LoggerScope(bool withTime) { previous = threadScope.Value; threadScope.Value = this; WithTime = withTime; }
public static Task LoadFromManager(this ExtensionCollection extensions, Manager manager, LoggerScope logger) { if (manager.HasInitialized) { foreach (ExtensionMetadata v in manager.GetExtensions()) { try { ExtensionLoader loader = new ExtensionLoader(v.RootPath, v.Name); extensions.Load(loader); } catch { logger.Warning($"Load extension at {v.RootPath} failed."); } } } return(Task.CompletedTask); }
public TestHost(LoggerScope scope) => Scope = scope;