Example #1
0
        public void Ctor_DeclareLogObjectWithNullOutput_ExceptionThrown()
        {
            ILogOutput         outLog         = null;
            ILogEntryFormatter entryFormatter = new FileFormatter();

            Assert.Throws <ArgumentNullException>(() => new Log(outLog, entryFormatter));
        }
Example #2
0
 static Log()
 {
     prefixedLogs     = new Dictionary <string, ILogOutput>();
     prefixedLogsLock = new object();
     outLock          = new object();
     output           = new LogConsoleOutput();
 }
Example #3
0
        private void AddEntry(LogEntry entry, object context)
        {
            // Check whether the message contains null characters. If it does, crop it, because it's probably broken.
            int nullCharIndex = entry.Message.IndexOf('\0');

            if (nullCharIndex != -1)
            {
                entry.Message = entry.Message
                                .Substring(0, Math.Min(nullCharIndex, 50)) +
                                " | Contains '\0' and is likely broken.";
            }

            // Forward the message to all outputs
            lock (_outputLock) {
                for (int i = 0; i < _outputs.Count; i++)
                {
                    ILogOutput log = _outputs[i];
                    try
                    {
                        log.Write(this, entry, context);
                    }
                    catch (Exception)
                    {
                        // Don't allow log outputs to throw unhandled exceptions,
                        // because they would result in another log - and more exceptions.
                    }
                }
            }
        }
Example #4
0
        public static void SetLogOutput(ILogOutput log, LogSeverity minSeverity = LogSeverity.Info)
        {
            Debug.Assert(LogOutput == null);

            LogOutput   = log;
            MinSeverity = minSeverity;
        }
Example #5
0
        /// <summary>
        /// Underlying method actually called through to by the Matches(Object) method
        ///
        /// Simply tries to check if anything has been logged at a level above the minimum threshold specified
        /// </summary>
        /// <param name="logOutput_"></param>
        /// <returns></returns>
        public bool Matches(ILogOutput logOutput_)
        {
            var logLevelNames = Enum.GetNames(typeof(LogLevel));

            foreach (var logLevelName in logLevelNames)
            {
                var logLevel = LogLevelExtensions.Parse(logLevelName);

                if (ThresholdLogLevel >= logLevel)
                {
                    continue;
                }

                if (!logOutput_.LogMessages[logLevel].Any())
                {
                    continue;
                }

                _errorMessage.Append("Log output contains messages logged at level [");
                _errorMessage.Append(logLevel.ToLogString());
                _errorMessage.Append("] when no messages above level [");
                _errorMessage.Append(ThresholdLogLevel.ToLogString());
                _errorMessage.Append("] were expected");
                return(false);
            }

            return(true);
        }
Example #6
0
 public ImageStore(IClusterConnection clusterConnection, ILogOutput logger)
     : base(clusterConnection, logger)
 {
     retryPolicy = Policy
                   .HandleResult <HttpResponseMessage>(r => !r.IsSuccessStatusCode)
                   .WaitAndRetryAsync(5, i => TimeSpan.FromSeconds(Math.Pow(2, i)));
 }
Example #7
0
 /// <summary>
 /// Removes a certain output.
 /// </summary>
 /// <param name="writer"></param>
 public void RemoveOutput(ILogOutput writer)
 {
     lock (this.syncObj)
     {
         this.output.Remove(writer);
         this.syncOutput = this.output.ToArray();
     }
 }
 public AssignmentGraphIndexer(IInstructionParser instructionParser,
                               ITripleStore tripleStore,
                               ILogOutput logOutput)
 {
     _instructionParser = instructionParser;
     _tripleStore       = tripleStore;
     _logOutput         = logOutput;
 }
Example #9
0
 public static void RemoveGlobalOutput(ILogOutput output)
 {
     _globalLogOutput.Remove(output);
     foreach (Log log in All)
     {
         log.RemoveOutput(output);
     }
 }
Example #10
0
 /// <summary>
 /// Adds an output to write log entries to.
 /// </summary>
 /// <param name="writer"></param>
 public void AddOutput(ILogOutput writer)
 {
     lock (this.syncObj)
     {
         this.output.Add(writer);
         this.syncOutput = this.output.ToArray();
     }
 }
Example #11
0
 public CallTreeWalker(IMethodIndexer methodIndexer,
                       IDatabaseResolver databaseResolver,
                       ILogOutput logOutput)
 {
     _methodIndexer    = methodIndexer;
     _databaseResolver = databaseResolver;
     _logOutput        = logOutput;
     _methodNodeLookup = new Dictionary <string, MethodNode>();
 }
Example #12
0
        public ConcurrentLogger(ApplicationLevel applicationLevel, ILogOutput output)
        {
            ContractAssertions.IsNotNull(output, nameof(output));

            _output           = output;
            _applicationLevel = applicationLevel;

            _enqueueMessage = false;
        }
Example #13
0
 /// <summary>
 /// Internal to make it accessable to unittests. Don't use this constructor unless you know what you're doing!
 /// </summary>
 /// <param name="logOutput"></param>
 /// <param name="logFormatter"></param>
 internal Log(ILogOutput logOutput, ILogEntryFormatter logFormatter)
 {
     if (logOutput == null || logFormatter == null)
     {
         throw new ArgumentNullException("Log Output parameter or Formatter parameter is null.");
     }
     _logOutput    = logOutput;
     _logFormatter = logFormatter;
 }
Example #14
0
 public void PopIndent()
 {
     lock (_outputLock) {
         for (int i = 0; i < _outputs.Count; i++)
         {
             ILogOutput log = _outputs[i];
             try { log.PopIndent(); }
             catch (Exception) {}
         }
     }
 }
Example #15
0
 /// <summary>
 /// Removes the specified <see cref="ILogOutput"/> from every log global channel.
 /// </summary>
 /// <param name="output"></param>
 public static void RemoveGlobalOutput(ILogOutput output)
 {
     lock (syncObj)
     {
         globalOutput.Remove(output);
         syncOutput = globalOutput.ToArray();
         foreach (Log log in logs)
         {
             log.RemoveOutput(output);
         }
     }
 }
Example #16
0
 /// <summary>
 /// Adds the specified <see cref="ILogOutput"/> to every log global channel.
 /// </summary>
 /// <param name="output"></param>
 public static void AddGlobalOutput(ILogOutput output)
 {
     lock (syncObj)
     {
         globalOutput.Add(output);
         syncOutput = globalOutput.ToArray();
         foreach (Log log in logs)
         {
             log.AddOutput(output);
         }
     }
 }
Example #17
0
        public static void AddGlobalOutput(ILogOutput output)
        {
            if (_globalLogOutput.Contains(output))
            {
                return;
            }

            _globalLogOutput.Add(output);
            foreach (Log log in All)
            {
                log.AddOutput(output);
            }
        }
Example #18
0
        public static void RegisterLogOutput(ILogOutput output, string logCategory)
        {
            if (CategoryOutputs.ContainsKey(logCategory) == false)
            {
                CategoryOutputs[logCategory] = new List <ILogOutput>();
            }

            List <ILogOutput> outputs = CategoryOutputs[logCategory];

            if (outputs.Contains(output) == false)
            {
                outputs.Add(output);
            }
        }
        static Logger()
        {
            _logOutput = new ConsoleLogOutput();
            AppDomain.CurrentDomain.UnhandledException += (sender, args) => Error(args.ExceptionObject);

#if DEBUG
            _debugEnabled    = true;
            LogCallingMethod = true;
#else
            _debugEnabled    = false; // can be set via property
            LogCallingMethod = false;
#endif
            singleThreaded = true;

            Initialize();
        }
Example #20
0
 public AnalysisEngine(IAssignmentGraphIndexer assignmentGraphIndexer,
                       IAssignmentGraphWalker assignmentGraphWalker,
                       IMethodIndexer methodIndexer,
                       IDelegateIndexer delegateIndexer,
                       ICallTreeWalker callTreeWalker,
                       ITypeService typeService,
                       ILogOutput logOutput)
 {
     _assignmentGraphIndexer = assignmentGraphIndexer;
     _assignmentGraphWalker  = assignmentGraphWalker;
     _methodIndexer          = methodIndexer;
     _delegateIndexer        = delegateIndexer;
     _callTreeWalker         = callTreeWalker;
     _typeService            = typeService;
     _logOutput = logOutput;
 }
Example #21
0
        public static void Obfuscate(AssemblyDefinition assembly, ILogOutput logOutput)
        {
            StartupSettings();
            logOutput.WriteMessage("Obfuscator module written by Marwix (2016).");
            logOutput.WriteMessage("---------------------------------------------------");

            var startTime = DateTime.Now;

            logOutput.WriteMessage("Started obfuscation process at " + startTime);

            var context = new ObfuscationContext(assembly, logOutput);

            var tasks = new ObfuscatorTask[]
            {
                new JunkCodeGenerationTask(),
                new SymbolRenamingTask(),
            };

            foreach (var task in tasks)
            {
                logOutput.WriteMessage("Initializing " + task.Name + "...");
                task.Initialize(context);
            }

            foreach (var task in tasks)
            {
                logOutput.WriteMessage("Applying " + task.Name + "...");
                task.ApplyAll(context);
            }

            foreach (var task in tasks)
            {
                logOutput.WriteMessage("Finalizing " + task.Name + "...");
                task.Finalize(context);
            }

            var endTime = DateTime.Now;

            logOutput.WriteMessage("---------------------------------------------------");
            logOutput.WriteMessage("Finished obfuscation process at " + endTime);
            logOutput.WriteMessage("Duration: " + (endTime - startTime));
        }
Example #22
0
        public void Dispose()
        {
#if !UNITY_WEBGL || UNITY_EDITOR
            this.isDisposed = true;

            if (this.newJobEvent != null)
            {
                this.newJobEvent.Close();
                this.newJobEvent = null;
            }
#endif

            if (this.Output != null)
            {
                this.Output.Dispose();
                this.Output = new UnityOutput();
            }

            GC.SuppressFinalize(this);
        }
 public CertificateProcessor(ILogOutput scomms)
 {
     if (null == _serverComms)
     {
         lock (_locker)
         {
             if (null == _serverComms)
             {
                 _serverComms = scomms;
                 _ipTools     = new IPTools()
                 {
                     ServerComms = _serverComms
                 };
                 _netshWrapper = new NetshWrapper()
                 {
                     ServerComms = _serverComms
                 };
             }
         }
     }
 }
Example #24
0
        public GraphodeCodeAnalyzer(List <IDatabaseAccessDetector> dbAccessDetectors,
                                    IDatabaseFinder databaseFinder,
                                    IAnalysisEngine analysisEngine = null,
                                    ILogOutput logOutput           = null)
        {
            if (analysisEngine == null)
            {
                _analysisEngine = CodeFactory.BuildAnalysisEngine(dbAccessDetectors, databaseFinder);
            }
            else
            {
                _analysisEngine = analysisEngine;
            }

            if (logOutput == null)
            {
                _logOutput = CodeFactory.BuildLogOutput();
            }
            else
            {
                _logOutput = logOutput;
            }
        }
Example #25
0
 public static void RemoveGlobalOutput(ILogOutput output)
 {
     logGame.RemoveOutput(output);
     logCore.RemoveOutput(output);
     logEditor.RemoveOutput(output);
 }
Example #26
0
		/// <summary>
		/// Removes a certain output.
		/// </summary>
		/// <param name="writer"></param>
		public void RemoveOutput(ILogOutput writer)
		{
			this.strOut.Remove(writer);
		}
Example #27
0
		/// <summary>
		/// Unregisters a registered output.
		/// </summary>
		/// <param name="writer"></param>
		public void UnregisterOutput(ILogOutput writer)
		{
			this.strOut.Remove(writer);
		}
Example #28
0
 /// <summary>
 /// Removes a certain output.
 /// </summary>
 /// <param name="writer"></param>
 public void RemoveOutput(ILogOutput writer)
 {
     this.strOut.Remove(writer);
 }
Example #29
0
		/// <summary>
		/// Adds an output to write log entries to.
		/// </summary>
		/// <param name="writer"></param>
		public void AddOutput(ILogOutput writer)
		{
			this.strOut.Add(writer);
		}
Example #30
0
 public Application(IClusterConnection clusterConnection, ILogOutput logger)
     : base(clusterConnection, logger)
 {
 }
Example #31
0
 /// <summary>
 /// Adds an output to write log entries to.
 /// </summary>
 /// <param name="writer"></param>
 public void AddOutput(ILogOutput writer)
 {
     this.strOut.Add(writer);
 }
Example #32
0
 public void ToOutput(ILogOutput output)
 {
     output.SetContext(_flowStructure.Context);
     _flowStructure.Output = output;
 }
Example #33
0
 public static void ClearLogOutput()
 {
     LogOutput = null;
 }
Example #34
0
 public ThreadedLogger()
 {
     this.Level  = UnityEngine.Debug.isDebugBuild ? Loglevels.Warning : Loglevels.Error;
     this.Output = new UnityOutput();
 }
Example #35
0
 public static void AddGlobalOutput(ILogOutput output)
 {
     logGame.AddOutput(output);
     logCore.AddOutput(output);
     logEditor.AddOutput(output);
 }
Example #36
0
        public static void UnregisterLogOutput(ILogOutput output, string logCategory)
        {
            List <ILogOutput> outputs = CategoryOutputs.ContainsKey(logCategory) ? CategoryOutputs[logCategory] : null;

            outputs?.Remove(output);
        }
Example #37
0
		/// <summary>
		/// Registers an output to write log entries to.
		/// </summary>
		/// <param name="writer"></param>
		public void RegisterOutput(ILogOutput writer)
		{
			this.strOut.Add(writer);
		}
Example #38
0
        /// <summary>
        /// Internal to make it accessable to unittests. Don't use this constructor unless you know what you're doing!
        /// </summary>
        /// <param name="logOutput"></param>
        /// <param name="logFormatter"></param>
        internal Log(ILogOutput logOutput, ILogEntryFormatter logFormatter)
        {

            if (logOutput == null || logFormatter == null)
                throw new ArgumentNullException("Log Output parameter or Formatter parameter is null.");
            _logOutput = logOutput;
            _logFormatter = logFormatter;
        }