private void WriteEntry(LogLevel level, string message, Exception exception) { Contract.Requires<ArgumentNullException>(!String.IsNullOrEmpty(message)); // find any filter that says no to logging Contract.Assume(_filters != null); if (_filters.Any(filter => !filter.CanLog(_loggedType, level))) { Console.WriteLine("Filter blocks"); return; } StackFrame[] frames = new StackTrace(2).GetFrames(); if (frames != null) frames = frames.Take(5).ToArray(); string userName = Thread.CurrentPrincipal.Identity.Name; if (string.IsNullOrEmpty(userName)) userName = Environment.UserName; var threadId = Thread.CurrentThread.ManagedThreadId; if (threadId<= 0) throw new InvalidOperationException("Expected to get a valid thread id."); Contract.Assume(_loggedType != null); var entry = new LogEntry(_loggedType, level, DateTime.Now, threadId, userName, message) {Exception = exception, StackFrames = frames}; foreach (var target in _targets) { target.Enqueue(entry); } }