Exemplo n.º 1
0
        public long Begin(AuditTrailViewModel sender, AuditTrail message)
        {
            fileAuditTrailWriter?.Begin(sender, message);
            //AuditTrailWriterHelper.LogsAdd(sender, message);
            //AuditTrailWriterHelper.WriteLineFile(sender, message, this.outputFile, DebugOutput);

            return(AuditTrailWriterHelper.BeginWriteDB(_dBSQLViewModel, sender, message));
        }
        public void End(AuditTrailViewModel sender, long parent, ErrorLevel errorLevel, string message, string dataOutType, string dataOut)
        {
            AuditTrail at = new AuditTrail {
                Level = errorLevel, Message = message, DataOutType = dataOutType, DataOut = dataOut
            };

            WriteLine(sender, at);
        }
Exemplo n.º 3
0
        public void WriteLine(AuditTrailViewModel sender, AuditTrail message)
        {
            fileAuditTrailWriter?.WriteLine(sender, message);
            //AuditTrailWriterHelper.LogsAdd(sender, message);

            //// File in first ( Wanao Specs ...)
            //AuditTrailWriterHelper.WriteLineFile(sender, message, this.outputFile, DebugOutput);

            AuditTrailWriterHelper.WriteLineDB(_dBSQLViewModel, sender, message);
        }
Exemplo n.º 4
0
        public void End(AuditTrailViewModel sender, long parent, ErrorLevel errorLevel, string message, string dataOutType, string dataOut)
        {
            AuditTrail at = new AuditTrail {
                Level = errorLevel, Message = message, DataOutType = dataOutType, DataOut = dataOut
            };

            fileAuditTrailWriter?.End(sender, parent, errorLevel, message, dataOutType, dataOut);

            //AuditTrailWriterHelper.WriteLineFile(sender, at, this.outputFile, DebugOutput);
            //// ?? AuditTrailWriterHelper.LogsAdd(sender, message);

            AuditTrailWriterHelper.EndWriteDB(_dBSQLViewModel, parent, errorLevel, message, dataOutType, dataOut);
        }
        // - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -

        public static bool EndWriteDB(DBSQLViewModel dBSQLViewModel, Int64 parent, ErrorLevel errorLevel, string message, string dataOutType, string dataOut)
        {
            long Ticks = DateTime.Now.Ticks;

            var at = DB_SQL.QueryFirst <AuditTrail>(dBSQLViewModel, "select * from AuditTrail where PK=" + parent);

            if (at != null)
            {
                at.Level       = errorLevel;
                at.Ticks       = Ticks - at.Ticks;
                at.DataOutType = dataOutType;
                at.DataOut     = dataOut;
                at.Parent      = -1; // ChM 20180514 pour simplifier requetes exploitations begin sans end

                var endAT = new AuditTrail();
                endAT.Application = at.Application;
                endAT.TerminalID  = at.TerminalID;
                endAT.TerminalIP  = at.TerminalIP;
                endAT.FKUser      = at.FKUser;
                endAT.ItemID      = at.ItemID;
                endAT.ItemType    = at.ItemType;
                endAT.IsBusiness  = at.IsBusiness;
                endAT.Tag         = at.Tag;
                endAT.Parent      = parent;
                endAT.Message     = message;
                endAT.Level       = errorLevel;
                endAT.DataOutType = dataOutType;
                endAT.DataOut     = dataOut;

                DB_SQL.Insert(dBSQLViewModel, endAT);

                return(DB_SQL.Update(dBSQLViewModel, at));
            }
            else
            {
                return(false);
            };
        }
        public void WriteLine(AuditTrailViewModel sender, AuditTrail message)
        {
            try
            {
                string Line = sender.FormatLine(message);

                if (DebugOutput)
                {
                    System.Diagnostics.Debug.WriteLine(Line);
                }

                File.AppendAllLines(outputFile, new[] { Line });

                if ((message.Level == ErrorLevel.Critical) && (string.IsNullOrEmpty(message.DataOut)))
                {
                    File.AppendAllLines(outputFile, new[] { message.DataOut + Environment.NewLine });
                }
                ;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("AuditTrailViewModel: " + ex.Message);
            };
        }
 public long Begin(AuditTrailViewModel sender, AuditTrail message)
 {
     WriteLine(sender, message);
     return(1);
 }
Exemplo n.º 8
0
        public void AuditTrail_WithStack()
        {
            var at = AuditTrail.WithStack(ErrorLevel.Log, "tag", "message");

            Assert.AreEqual(true, at.DataIn.Contains("AuditTrail_WithStack"));
        }
Exemplo n.º 9
0
        public void AuditTrail_FromHere()
        {
            var at = AuditTrail.FromHere(ErrorLevel.Log, "tag", "message");

            Assert.AreEqual(true, at.DataIn.Contains("AuditTrail_FromHere"));
        }
        // - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -

        public static long BeginWriteDB(DBSQLViewModel dBSQLViewModel, AuditTrailViewModel sender, AuditTrail message)
        {
            long Result = -1;

            try
            {
                Result = DB_SQL.InsertGetPK(dBSQLViewModel, message);
                if (!string.IsNullOrEmpty(dBSQLViewModel.LastError))
                {
                    Debug.WriteLine("AuditTrailViewWriter LastError: " + dBSQLViewModel.LastError + Environment.NewLine
                                    + "AuditTrailViewWriter LastQuery: " + dBSQLViewModel.LastQuery);

                    Log.Write(new AuditTrail
                    {
                        Message = "AuditTrailViewWriter LastError: " + dBSQLViewModel.LastError + Environment.NewLine
                                  + "AuditTrailViewWriter LastQuery: " + dBSQLViewModel.LastQuery
                    });
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("AuditTrailViewWriter: " + ex.Message);

                Log.Write(new AuditTrail
                {
                    Message = "AuditTrailViewWriter: " + ex.Message
                });
            };

            return(Result);
        }
        // - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -  - -

        public static void WriteLineDB(DBSQLViewModel dBSQLViewModel, AuditTrailViewModel sender, AuditTrail message)
        {
            if (dBSQLViewModel == null)
            {
                return;
            }

            try
            {
                DB_SQL.Insert(dBSQLViewModel, message);

                if (!string.IsNullOrEmpty(dBSQLViewModel.LastError))
                {
                    Debug.WriteLine("AuditTrailViewModel LastError: " + dBSQLViewModel.LastError + Environment.NewLine
                                    + "AuditTrailViewModel LastQuery: " + dBSQLViewModel.LastQuery);

                    //Log.Debug(new AuditTrail
                    //{
                    //   Message = "AuditTrailViewWriter LastError: " + dBSQLViewModel.LastError + Environment.NewLine
                    //                                       + "AuditTrailViewWriter LastQuery: " + dBSQLViewModel.LastQuery
                    //});
                }
                ;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("AuditTrailViewModel: " + ex.Message);

                //Log.Debug(new AuditTrail
                //{
                //   Message = "AuditTrailViewWriter: " + ex.Message
                //});
            };
        }
        public long Begin(AuditTrailViewModel sender, AuditTrail message)
        {
            //AuditTrailWriterHelper.LogsAdd(sender, message);

            return(AuditTrailWriterHelper.BeginWriteDB(_dBSQLViewModel, sender, message));
        }
        public void WriteLine(AuditTrailViewModel sender, AuditTrail message)
        {
            //AuditTrailWriterHelper.LogsAdd(sender, message);

            AuditTrailWriterHelper.WriteLineDB(_dBSQLViewModel, sender, message);
        }
        public void WriteLine(AuditTrailViewModel sender, AuditTrail message)
        {
            if (_FileType == FileTypes.FullJSON)
            {
                try
                {
                    string json = "";

                    if (System.IO.File.Exists(outputFile))
                    {
                        json = File.ReadAllText(outputFile);
                    }
                    ;

                    List <AuditTrail> lines = null;

                    if (string.IsNullOrEmpty(json))
                    {
                        lines = new List <AuditTrail>();
                    }
                    else
                    {
                        lines = JsonSerializer.Deserialize <List <AuditTrail> >(json);
                    };

                    lines.Add(message);

                    json = JsonSerializer.Serialize(lines, new JsonSerializerOptions {
                        IgnoreNullValues = true
                    });

                    File.WriteAllText(outputFile, json, System.Text.Encoding.ASCII);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);

#if DEBUG
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
                    ;
#endif
                };
            }
            else
            {
                try
                {
                    string Line = JsonSerializer.Serialize(message, new JsonSerializerOptions
                    {
                        IgnoreNullValues = true,
                    });

                    if (System.IO.File.Exists(outputFile))
                    {
                        File.AppendAllLines(outputFile, new[] { "," + Line });
                    }
                    else
                    {
                        File.AppendAllLines(outputFile, new[] { "{" + Line });
                    };
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("AuditTrailViewModel: " + ex.Message);
                };
            };
        }
Exemplo n.º 15
0
 public void WriteLine(AuditTrailViewModel sender, AuditTrail message)
 {
     System.Diagnostics.Debug.WriteLine(message.Message);
 }