Example #1
0
 private static void Flush()
 {
     if (LogQueue.Count > 0)
     {
         lock (LogQueue)
         {
             LogPersister.PersisLogs(LogQueue);
             LogQueue.Clear();
         }
     }
 }
Example #2
0
        public void Log(Log log)
        {
            var internalLog = log.InternalLog;

            internalLog.ContextId      = ContextId;
            internalLog.LogDate        = DateTime.Now;
            internalLog.ServerName     = internalLog.ServerName ?? Environment.MachineName;
            internalLog.LogType        = internalLog.LogType ?? LogTypes.Info.ToString();
            internalLog.Message        = internalLog.Message ?? "";
            internalLog.MessageCode    = internalLog.MessageCode ?? "";
            internalLog.ServiceName    = internalLog.ServiceName ?? "";
            internalLog.FunctionName   = internalLog.FunctionName ?? "";
            internalLog.ResponseStatus = internalLog.ResponseStatus ?? "";
            internalLog.ClientIp       = internalLog.ClientIp ?? "";

            log.IsLogged          = true;
            log.DurationInSeconds = DateTime.Now.Subtract(internalLog.RequestDate).TotalSeconds;

            lock (LogQueue)
            {
                if (BufferEnabled)
                {
                    LogQueue.Add(log);
                }
                else
                {
                    LogPersister.PersistLog(log);
                }
            }

#if DEBUG
            Console.WriteLine("ContextId: {0}, LogDate: {1}, ServerName: {2}, LogType: {3}, Message: {4}, MessageCode: {5}, " +
                              "ServiceName: {6}, FunctionName: {7}, ResponseStatus: {8}, ClientIp: {9}, IsLogged: {10}, DurationInSeconds: {11}",
                              internalLog.ContextId, internalLog.LogDate, internalLog.ServerName, internalLog.LogType, internalLog.Message,
                              internalLog.MessageCode, internalLog.ServiceName, internalLog.FunctionName, internalLog.ResponseStatus,
                              internalLog.ClientIp, log.IsLogged, log.DurationInSeconds);
            System.Threading.Thread.Sleep(1000);
#endif
        }