예제 #1
0
 public ReturnModel <bool> DeleteLog(StoredLogType logType, string id)
 {
     try
     {
         appLogWriter.Delete <AppLog>(x => x.LogId == SafeUtils.Guid(id) && x.LogType == (int)logType);
         return(new ReturnModel <bool>(true));
     }
     catch (Exception ex)
     {
         log.Error(ex, "Error when getting Deleting App Log  - id = " + id);
         return(new ReturnModel <bool>(ex));
     }
 }
예제 #2
0
        public ReturnModel <bool> DeleteLog(StoredLogType logType, string id)
        {
            try
            {
                using (var session = appLogProvider.OpenSession <AppLog>())
                {
                    //fixme: delete by 100 items at a time
                    var items = session.Query().Where(x => x.LogId == SafeUtils.Guid(id) && x.LogType == (int)logType).ToArray();
                    session.Delete(items);
                }

                return(new ReturnModel <bool>(true));
            }
            catch (Exception ex)
            {
                log.Error(ex, "Error when getting Deleting App Log  - id = " + id);
                return(new ReturnModel <bool>(ex));
            }
        }
예제 #3
0
        static AppLog GetAppLogFromLine(string fileName, string line, string extractionPattern, string extractionPatternForFileName)
        {
            AppLog log = new AppLog();
            Match  match;

            if (String.IsNullOrEmpty(extractionPattern))
            {
                match = defaultLogExpression.Match(line);
            }
            else
            {
                Regex expression = new Regex(extractionPattern);
                match = expression.Match(line);
            }

            if (match.Success)
            {
                if (match.Groups["longdatetime"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Longdate = SafeUtils.DateTime(match.Groups["longdatetime"].Value);
                }
                else if (match.Groups["shorttime"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Longdate = SafeUtils.DateTime(match.Groups["shorttime"].Value);

                    if (match.Groups["shortdate"].Value.IsTrimmedStringNotNullOrEmpty())
                    {
                        var shortDate = DateTime.UtcNow;
                        shortDate    = SafeUtils.DateTime(match.Groups["shortdate"].Value);
                        log.Longdate = log.Longdate.UpdateDatePart(shortDate.Date);
                    }
                    else
                    {
                        var shortFilename = Path.GetFileName(fileName);
                        var expression    = new Regex(extractionPatternForFileName);
                        var fileNameMatch = expression.Match(shortFilename ?? "");

                        if ((fileNameMatch.Groups["year"].Value.IsTrimmedStringNotNullOrEmpty()) &&
                            (fileNameMatch.Groups["month"].Value.IsTrimmedStringNotNullOrEmpty()) &&
                            (fileNameMatch.Groups["day"].Value.IsTrimmedStringNotNullOrEmpty()))
                        {
                            log.Longdate = log.Longdate.UpdateDatePart(SafeUtils.Int(fileNameMatch.Groups["year"].Value), SafeUtils.Int(fileNameMatch.Groups["month"].Value), SafeUtils.Int(fileNameMatch.Groups["day"].Value));
                        }
                        else
                        {
                            Console.WriteLine("Unable to get the Log Date for Line - " + line);
                        }
                    }
                }
                else
                {
                    log.Longdate = DateTime.UtcNow;
                }

                if (match.Groups["loglevel"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Severity = match.Groups["loglevel"].Value;
                }


                if (match.Groups["machine"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.MachineName = match.Groups["machine"].Value;
                }
                else
                {
                    log.MachineName = Environment.MachineName;
                }

                if (SafeUtils.Int(match.Groups["processid"].Value) != 0)
                {
                    log.ProcessId = SafeUtils.Int(match.Groups["processid"].Value);
                }

                if (SafeUtils.Int(match.Groups["threadid"].Value) != 0)
                {
                    log.ThreadId = SafeUtils.Int(match.Groups["threadid"].Value);
                }

                if (match.Groups["function"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.CurrentFunction = match.Groups["function"].Value;
                }

                if (match.Groups["filename"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.CurrentSourceFilename = match.Groups["filename"].Value;
                }

                if (SafeUtils.Int(match.Groups["linenumber"].Value) != 0)
                {
                    log.CurrentSourceLineNumber = SafeUtils.Int(match.Groups["linenumber"].Value);
                }

                if (match.Groups["tag"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.CurrentTag = match.Groups["tag"].Value;
                }

                if (match.Groups["user"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.UserIdentity = match.Groups["user"].Value;
                }

                if (match.Groups["ip"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.RemoteAddress = match.Groups["ip"].Value;
                }

                if (match.Groups["result"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Result = match.Groups["result"].Value;
                }

                if (match.Groups["loglevel"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.ElapsedTime = SafeUtils.Double(match.Groups["elapsedtime"].Value);
                }

                if (match.Groups["message"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Message = match.Groups["message"].Value;
                }

                if (match.Groups["log-id"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.LogId = SafeUtils.Guid(match.Groups["log-id"].Value);
                }

                if (match.Groups["log-type"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.LogType = SafeUtils.Int(match.Groups["LogType"].Value);
                }

                if (match.Groups["application-Id"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.ApplicationId = match.Groups["application-Id"].Value;
                }

                if (match.Groups["corelation-id"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.CorelationId = match.Groups["corelation-id"].Value;
                }

                if (match.Groups["receivedDateAsTicks"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.ReceivedDateAsTicks = SafeUtils.Long(match.Groups["receivedDateAsTicks"].Value);
                }

                if (match.Groups["longdate-as-ticks"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.LongdateAsTicks = SafeUtils.Long(match.Groups["longdate-as-ticks"].Value);
                }

                if (match.Groups["app"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.App = match.Groups["app"].Value;
                }

                if (match.Groups["module"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Module = match.Groups["module"].Value;
                }

                if (match.Groups["result-code"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.ResultCode = SafeUtils.Int(match.Groups["result-code"].Value);
                }

                if (match.Groups["function-name"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.FunctionName = match.Groups["function-name"].Value;
                }

                if (match.Groups["start-time"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.StartTime = SafeUtils.DateTime(match.Groups["start-time"].Value);
                }

                if (match.Groups["result"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Result = match.Groups["result"].Value;
                }

                if (match.Groups["request"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Request = match.Groups["request"].Value;
                }

                if (match.Groups["response"].Value.IsTrimmedStringNotNullOrEmpty())
                {
                    log.Response = match.Groups["response"].Value;
                }
            }
            return(log);
        }
예제 #4
0
 public ReturnModel <bool> DeleteLog(StoredLogType logType, string id)
 {
     dbManager.Delete <AppLog>(x => x.LogType == (int)logType && x.LogId == SafeUtils.Guid(id));
     return(ReturnModel <bool> .Success(true));
 }