Esempio n. 1
0
        public void Log(InfLogEntry logEntry)
        {
            var logEntryString = new StringBuilder();

            using (var xmlWriter = XmlWriter.Create(logEntryString, _xmlWriterSettings))
            {
                xmlWriter.WriteStartElement("InfLogEntry");

                xmlWriter.WriteStartElement("SerialNumber");
                xmlWriter.WriteValue(logEntry.SerialNumber);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("LogDate");
                xmlWriter.WriteValue(string.Format(CultureInfo.InvariantCulture, "{0:yyyy-MM-dd hh:mm:ss.fff tt}", DateTime.Now));
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("Source");
                xmlWriter.WriteValue(logEntry.Source);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("Message");
                xmlWriter.WriteValue(logEntry.Message);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("UserName");
                xmlWriter.WriteValue(logEntry.UserName);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("ServerAddress");
                xmlWriter.WriteValue(logEntry.ServerAddress);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("ServerHostname");
                xmlWriter.WriteValue(logEntry.ServerHostname);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("ClientAddress");
                xmlWriter.WriteValue(logEntry.ClientAddress);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteStartElement("ClientHostname");
                xmlWriter.WriteValue(logEntry.ClientHostname);
                xmlWriter.WriteEndElement();

                xmlWriter.WriteEndElement(); // </InfLogEntry >
                xmlWriter.Flush();
            }

            File.AppendAllText(LogFileName, logEntryString.ToString());
        }
Esempio n. 2
0
 public void Log(InfLogEntry logEntry)
 {
     using (var transaction = new TransactionScope(TransactionScopeOption.Suppress))
     {
         using (var sqlHelper = new InfSqlHelper())
         {
             sqlHelper.ExecuteNonQueryProcedure(
                 "dbo.PSP_InfLog_Insert",
                 new SqlParameter("@SerialNumber", logEntry.SerialNumber),
                 new SqlParameter("@LogLevel", logEntry.LogLevel),
                 new SqlParameter("@Source", logEntry.Source),
                 new SqlParameter("@Message", logEntry.Message),
                 new SqlParameter("@UserName", logEntry.UserName),
                 new SqlParameter("@ServerAddress", logEntry.ServerAddress),
                 new SqlParameter("@ServerHostname", logEntry.ServerHostname),
                 new SqlParameter("@ClientAddress", logEntry.ClientAddress),
                 new SqlParameter("@ClientHostname", logEntry.ClientHostname));
         }
     }
 }
Esempio n. 3
0
        public static string Log(InfLogEntry logEntry)
        {
            if (logEntry.LogLevel > ApplicationLogLevel)
            {
                return(null);
            }

            logEntry.SerialNumber = GetSerialNumber();
            if (string.IsNullOrWhiteSpace(logEntry.Source))
            {
                logEntry.Source = GetSource();
            }

            logEntry.ServerAddress  = GetServerAddress();
            logEntry.ServerHostname = GetServerHostname();
            logEntry.ClientAddress  = GetClientAddress();
            logEntry.ClientHostname = GetClientHostname();

            if (string.IsNullOrWhiteSpace(logEntry.UserName))
            {
                logEntry.UserName = GetUserName();
            }

            ThreadPool.QueueUserWorkItem(
                delegate(object state)
            {
                for (var i = 0; i < loggerInstances.Length; i++)
                {
                    try
                    {
                        // todo: log logging errors
                        loggerInstances[i].Log(logEntry);
                    }
                    catch { }
                }
            });

            return(logEntry.SerialNumber);
        }
 public void Log(InfLogEntry logEntry)
 {
     // todo: implement
     throw new NotImplementedException();
 }