Ejemplo n.º 1
0
        public static void LogMessage(string Message,
                                      [CallerMemberName] string memberName    = "",
                                      [CallerFilePath] string sourceFilePath  = "",
                                      [CallerLineNumber] int sourceLineNumber = 0)
        {
            Debug.WriteLine(Message);

            if (!LoggingEnabled)
            {
                return;
            }

            try
            {
                if (cacheLock.TryEnterWriteLock(timeout))
                {
                    if (LogFilePath == null)
                    {
                        FileTraceWriter.Initialise();
                    }

                    using (StreamWriter sw = File.AppendText(LogFilePath))
                    {
                        sw.WriteLine($"{DateTime.Now}: {memberName}: Line {sourceLineNumber}: " + Message);
                    }
                }
            }
            catch (Exception exc)
            {
                // to do
            }
        }
Ejemplo n.º 2
0
 internal static FileTraceWriter GetInstance()
 {
     if (_singleton == null)
     {
         _singleton = new FileTraceWriter();
     }
     return(_singleton);
 }
Ejemplo n.º 3
0
        public static void LogError(Exception exc, string message,
                                    [CallerMemberName] string memberName    = "",
                                    [CallerFilePath] string sourceFilePath  = "",
                                    [CallerLineNumber] int sourceLineNumber = 0)
        {
            if (exc == null)
            {
                Debug.WriteLine("Error, but no exception to process");
                return;
            }

            string errMsg = message;

            try
            {
                errMsg = $"ERROR: {DateTime.Now}: {memberName}: Line {sourceLineNumber}: {exc}{Environment.NewLine}";
            }
            catch (Exception ex)
            {
                errMsg = "ERROR, Error: " + ex.Message;
            }

            Debug.WriteLine(errMsg);

            if (!LoggingEnabled)
            {
                return;
            }

            try
            {
                if (cacheLock.TryEnterWriteLock(timeout))
                {
                    if (LogFilePath == null)
                    {
                        FileTraceWriter.Initialise();
                    }

                    using (StreamWriter sw = File.AppendText(LogFilePath))
                    {
                        sw.WriteLine(errMsg);
                    }
                }
            }
            catch (Exception ex)
            {
                // to do
            }
        }