/// <summary>
        /// Log Exceptions.
        /// </summary>
        /// <param name="exceptions">Exception to be logged.</param>
        /// <returns>Operation result detailing whether log was successful.</returns>
        public OperationResult LogExceptions(params Exception[] exceptions)
        {
            var operation = Get.OperationResult(() => _logger.Log(_formatter.FormatException(exceptions)));

            ErrorLogged?.Invoke(this, new GenericEventArgs <bool>(operation.WasSuccessful));
            return(operation);
        }
        /// <summary>
        /// Log Exception.
        /// </summary>
        /// <param name="exceptions">Exceptions to be logged.</param>
        /// <returns>Operation result detailing whether log was successful.</returns>
        public OperationResult LogExceptions(params Exception[] exceptions)
        {
            var operation =
                _component.LogExceptions(exceptions);

            ErrorLogged?.Invoke(this, new GenericEventArgs <bool>(operation.WasSuccessful));
            return(operation);
        }
Esempio n. 3
0
 public void Log(string error)
 {
     if (String.IsNullOrWhiteSpace(error))
     {
         throw new ArgumentNullException();
     }
     LastError = error;
     ErrorLogged?.Invoke(this, Guid.NewGuid());
 }
Esempio n. 4
0
 public static void LogError(Exception e, String info = "", String extraInfo = "")
 {
     LogText += $"Error - {info}:\n{extraInfo}\n\n";
     try
     {
         ErrorLogged?.Invoke(e, info, extraInfo);
     }
     catch
     {
     }
 }
Esempio n. 5
0
        public void LogError(string errorThrower = null, string errorMessage = null, string systemError = null)
        {
            if (_internalOutput.HasFlag(Output.Console))
            {
                if (errorThrower != null)
                {
                    Console.WriteLine(errorThrower);
                }
                if (errorMessage != null)
                {
                    Console.WriteLine(errorMessage);
                }
                if (systemError != null)
                {
                    Console.WriteLine(systemError);
                }
            }

            if (_internalOutput.HasFlag(Output.MessageBox))
            {
                var mbMessage = "";

                if (errorMessage != null)
                {
                    mbMessage += errorMessage + "\n\n";
                }

                if (systemError != null)
                {
                    mbMessage += systemError;
                }


                if (errorThrower != null)
                {
                    MessageBox.Show(mbMessage, errorThrower);
                }
                else
                {
                    MessageBox.Show(mbMessage);
                }
            }

            if (_internalOutput.HasFlag(Output.FileLog))
            {
                //throw new NotImplementedException();
            }

            if (_internalOutput.HasFlag(Output.Event))
            {
                ErrorLogged?.Invoke(errorThrower, errorMessage, systemError);
            }
        }
Esempio n. 6
0
        public void LogError(string text)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                throw new ArgumentNullException(nameof(text));
            }

            LastError = text;

            _logger.LogError(text);

            ErrorLogged?.Invoke(this, Guid.NewGuid());
        }
Esempio n. 7
0
        public void Log(string error)
        {
            if (string.IsNullOrWhiteSpace(error))
            {
                throw new ArgumentNullException();
            }

            LastError = error;

            // Write the log to a storage
            // ...

            ErrorLogged?.Invoke(this, Guid.NewGuid());
        }
 public void Log(string error)
 {
     if (String.IsNullOrWhiteSpace(error))
     {
         //If my string is null tell me
         throw new ArgumentNullException();
     }
     else
     {
         //Store my error in a log
         lastError = error;
         ErrorLogged?.Invoke(this, Guid.NewGuid());
     }
 }
        public void Log(string error)
        {
            //3 test cases null, emptystring, string with white space
            if (String.IsNullOrWhiteSpace(error))
            {
                throw new ArgumentNullException();
            }

            LastError = error;

            // Write the log to a storage
            // ...

            ErrorLogged?.Invoke(this, Guid.NewGuid());
        }
        public void Log(string error)
        {
            //Test for:  null - "" (empty string) - " " (string with whitespace)
            if (String.IsNullOrWhiteSpace(error))
            {
                throw new ArgumentNullException();
            }

            LastError = error; //to test the test we can comment this out
                               //if test still passes the test is wrong

            // Write the log to a storage
            // ...

            ErrorLogged?.Invoke(this, Guid.NewGuid());
        }
Esempio n. 11
0
        public void Log(string error)
        {
            //Excecution paths
            // 1 test for null
            // 2. test ""
            // 3. test for " "
            if (String.IsNullOrWhiteSpace(error))
            {
                throw new ArgumentNullException();
            }

            LastError = error;

            // Write the log to a storage
            // ...

            ErrorLogged?.Invoke(this, Guid.NewGuid());
        }
Esempio n. 12
0
        /// <summary>
        /// Logs the specified exception.
        /// </summary>
        /// <param name="ex">The ex.</param>
        public static bool LogError(Exception ex, LogAction action)
        {
            try
            {
                Log.Error(ex, string.Empty);
                switch (action)
                {
                case LogAction.LogAndShow:
                    ErrorLogged?.Invoke(null, DateTime.Now + " : " + ex.Message);
                    break;

                case LogAction.LogAndThrow:
                    return(true);
                }
            }
            catch { }
            return(false);
        }
Esempio n. 13
0
        public void Log(string error)
        {
            // This Method has 3 TestCases
            // Null
            // ""
            // " "

            if (String.IsNullOrWhiteSpace(error))
            {
                throw new ArgumentNullException();
            }

            LastError = error;

            // Write the log to a storage
            // ...

            ErrorLogged?.Invoke(this, Guid.NewGuid());
        }
Esempio n. 14
0
        public void Log(string error)
        {
            //if(error == null || error.Trim() == "")

            //Asagidaki kod ile yukardaki arasinda bir temel de bir fark
            //yoktur. Sadece kod okunabilirligi ve karsilasilabielcek
            //hata oranini azaltmak amaci ile asagidaki yapi tercih
            //edilmelidir.

            if (String.IsNullOrWhiteSpace(error))
            {
                throw new ArgumentNullException();
            }


            LastError = error;

            ErrorLogged?.Invoke(this, Guid.NewGuid());
        }
Esempio n. 15
0
        public static void Error(Exception ex, [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
        {
            // caller info 를 제대로 찍기 위해서는
            // Error(string format, object o1 = null, object o2...) 를 부르지 말고 여기서 직접 처리해야 한다.

            //if (string.IsNullOrEmpty(format))
            //    return;

            string exceptionStr = ex.ToString();

            string text = null;

            if (CallerInfo == CallerInfo.ClassMethod) // 퍼포먼스 떨어짐
            {
                StackFrame frame = new StackFrame(1, false);
                text = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ERROR " + frame.GetMethod().DeclaringType.Name + "." + frame.GetMethod().Name + "] " +
                       exceptionStr;
            }
            else if (CallerInfo == CallerInfo.SourceLine) // 기본값
            {
                text = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ERROR " + sourceFilePath.Substring(sourceFilePath.LastIndexOf('\\') + 1) + " " + sourceLineNumber + "] " +
                       exceptionStr;
            }
            else // CallerInfo.NoCallerInfo
            {
                text = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " ERROR] " +
                       exceptionStr;
            }

            // thread-safe 인 _writer 를 점유하고 있는 놈이 완전히 처리하기 전에 불리는 count 를 센다.
            _bufferCount++;

            // 새로 생기거나 날짜가 바뀌면 새로운 _streamWriter 를 할당한다.
            if (_fileName == null || !_fileName.StartsWith(DateTime.Now.ToString("yyyyMMdd")))
            {
                lock (_writerCreateLock)
                {
                    if (_writer != null)
                    {
                        _writer.Close();
                    }

                    System.Reflection.Assembly assembly = System.Reflection.Assembly.GetEntryAssembly();
                    if (assembly == null) // unmanaged code 등에서 불리면 null 이 된다.
                    {
                        assembly = System.Reflection.Assembly.GetCallingAssembly();
                    }

                    _fileName = DateTime.Now.ToString("yyyyMMdd") + "." + assembly.GetName().Name + ".txt";

                    _writer = TextWriter.Synchronized(new StreamWriter(Path.Combine(_logFolderPath, _fileName), true)); // thread-safe
                }
            }

            // 쓴다.
            if (Async)
            {
                _writer.WriteLineAsync(text);
            }
            else
            {
                _writer.WriteLine(text);
                _writer.Flush();
            }

            // 버퍼에 쌓여있는 양을 처리하고 나면 동일한 양의 로그가 또 쌓여있는 상황을 이상적인 _bufferSize 로 본다.
            if (_bufferCount > _bufferSize)
            {
                _bufferSize = Math.Min(_bufferSize + 1, int.MaxValue);
            }
            else
            {
                _bufferSize = Math.Max(_bufferSize - 1, 0);
            }

            if (_bufferCount >= _bufferSize)
            {
                Flush();
            }

            if (ErrorOnConsole)
            {
                Console.WriteLine(text);
            }

            ErrorLogged?.Invoke(null, new LoggedEventArgs(text));
        }
Esempio n. 16
0
 protected static void OnErrorLogged(object sender, LogErrorEventArgs e)
 {
     ErrorLogged?.Invoke(sender, e);
 }
Esempio n. 17
0
 public virtual void OnErrorLogged()
 {
     ErrorLogged?.Invoke(this, _errorId);
 }
Esempio n. 18
0
 public static void Error(Exception exception, string message)
 {
     Instance?.Error(exception, message);
     ErrorLogged?.Invoke(null, new MessageWithExceptionLoggedEventArgs(message, exception));
 }
Esempio n. 19
0
 protected virtual void OnErrorLogged(Guid errorID) //Not Tested
 {
     ErrorLogged?.Invoke(this, errorID);
 }
Esempio n. 20
0
 /// <summary>
 /// Sends the error logged event to any registered listeners.
 /// </summary>
 /// <param name="message">
 /// The message to send
 /// </param>
 public static void SendErrorEvent(string message)
 {
     ErrorLogged?.Invoke(null, new MessageLoggedEventArgs(message));
 }
Esempio n. 21
0
 private void OnErrorLogged(Guid errorId)
 {
     ErrorLogged?.Invoke(this, errorId);
 }
Esempio n. 22
0
        //        public virtual void OnErrorLogged()
        //        {
        //            ErrorLogged?.Invoke(this, _errorId);
        //        }

        public virtual void OnErrorLogged(Guid errorId)
        {
            ErrorLogged?.Invoke(this, errorId);
        }
Esempio n. 23
0
 /// <summary>
 /// Logs an error.
 /// </summary>
 /// <param name="errorMessage">The error message.</param>
 public void Error(string errorMessage)
 {
     ErrorLogged.Raise(this, new EventArgs <string>(DateTime.Now.ToString("HH:mm:ss") + ": " + errorMessage));
 }
Esempio n. 24
0
 protected virtual void OnErrorLogged()
 {
     ErrorLogged?.Invoke(this, _errorId);
 }
 // This method is about implementation detail and hence not making it public and writing test cases on it
 // Hence, tomorrow even if we raise the event directly from the method and remove this method/pass a parameter to this method, nothing will break
 protected virtual void OnErrorLogged()
 {
     ErrorLogged?.Invoke(this, Guid.NewGuid());
 }
Esempio n. 26
0
 //don't write tests for this method
 protected virtual void OnErrorLogged(Guid errorId)
 {
     ErrorLogged?.Invoke(this, errorId);
 }
 public virtual void OnErrorLogged(Guid errorId) //Implementation detail
 {
     ErrorLogged?.Invoke(this, errorId);
 }