コード例 #1
0
ファイル: Program.cs プロジェクト: nmaliganis/igoodi
        private static LoggingModel CustomEnricherLogic(IHttpContextAccessor ctx)
        {
            var context = ctx.HttpContext;

            if (context == null)
            {
                return(null);
            }

            var loggingInfo = new LoggingModel
            {
                Path   = context.Request.Path.ToString(),
                Host   = context.Request.Host.ToString(),
                Method = context.Request.Method
            };

            var user = context.User;

            if (user?.Identity != null && user.Identity.IsAuthenticated)
            {
                loggingInfo.UserClaims =
                    user.Claims.Select(a => new KeyValuePair <string, string>(a.Type, a.Value)).ToList();
            }
            return(loggingInfo);
        }
コード例 #2
0
        public Task <LogResponseModel> LogAsync(LoggingModel logModel)
        {
            var appInfo      = logModel.AppInfo == null ? new ApplicationInfo() : logModel.AppInfo;
            var custId       = LogsForCustomer.None;
            var custLogLevel = ApiLogLevel.Information;

            if (logModel.CustomerLogLevel != null)
            {
                custId       = logModel.CustomerLogLevel.CustomerId;
                custLogLevel = logModel.CustomerLogLevel.LogLevel;
            }
            string message = $"\nLog raised with Id - {logModel.Id} at {logModel.LogRaisedAt}\n" +
                             $"from Service - {appInfo.ServiceName} And Application - {appInfo.AppName}\n" +
                             $"IP_Adress {appInfo.IPAdress} with Message {logModel.Message}\n" +
                             $"for Customer: {custId}\n" +
                             $"and Logging to ES at {DateTime.UtcNow}";

            _logger.Emit(custId, custLogLevel, logModel.Exception, message, logModel);


            var response = new LogResponseModel()
            {
                Id     = logModel.Id,
                Status = LogStatus.Completed
            };

            return(Task.FromResult(response));
        }
コード例 #3
0
 public JsonResult LogFEError([FromBody] LoggingModel inputParams)
 {
     return(new JsonResult
     {
         Data = LoggingService.LogFEException(inputParams.ErrorMsg, string.Format("Browser: {0}, Version: {1}", HttpContext.Current.Request.Browser.Browser, HttpContext.Current.Request.Browser.MajorVersion)),
         JsonRequestBehavior = JsonRequestBehavior.AllowGet
     });
 }
コード例 #4
0
        public LoggingViewModel()
        {
            _loggingCommand = new RelayCommand(checkCredentials, canExecuteLogginForm);
            _logingModel    = new LoggingModel();

            // subscribe to the change of the Model in order to validate the form, because 'canExecute' of the 'RelayCommand only execute
            // once, we should refresh it by calling RaiseCanExecuteChanged()
            _logingModel.FormIsValid += (o, e) => _loggingCommand.RaiseCanExecuteChanged();
        }
コード例 #5
0
    /// <summary>
    /// Initializes a new instance of the <see cref="EfLoggingProvider" /> class.
    /// </summary>
    /// <param name="shopContext">The shop context.</param>
    public EfLoggingProvider([NotNull] ShopContext shopContext)
    {
      Assert.ArgumentNotNull(shopContext, "shopContext");
      Assert.IsNotNullOrEmpty(shopContext.LoggingDatabaseName, "shopContext.LoggingDatabaseName");

      this.logEntryModel = new LoggingModel(shopContext.LoggingDatabaseName);
      this.loggingEntriesToAdd = new ConcurrentBag<LogEntry>();
      this.synchronizationPrimitive = new ReaderWriterLockSlim();
    }
コード例 #6
0
 /// <summary>
 /// constructor of LogViewModel
 /// </summary>
 public LogViewModel()
 {
     this.model             = new LoggingModel();
     model.PropertyChanged +=
         delegate(Object sender, PropertyChangedEventArgs e) {
         NotifyPropertyChanged(e.PropertyName);
     };
     this.model.getHistory();
 }
コード例 #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EfLoggingProvider" /> class.
        /// </summary>
        /// <param name="shopContext">The shop context.</param>
        public EfLoggingProvider([NotNull] ShopContext shopContext)
        {
            Assert.ArgumentNotNull(shopContext, "shopContext");
            Assert.IsNotNullOrEmpty(shopContext.LoggingDatabaseName, "shopContext.LoggingDatabaseName");

            this.logEntryModel            = new LoggingModel(shopContext.LoggingDatabaseName);
            this.loggingEntriesToAdd      = new ConcurrentBag <LogEntry>();
            this.synchronizationPrimitive = new ReaderWriterLockSlim();
        }
コード例 #8
0
        public static void AddLogMessage(LoggingModel logMessage, bool updateStatus)
        {
            lock (_logsLock)
            {
                Logs.Add(logMessage);
            }

            if (updateStatus)
            {
                _latestLogMessage = logMessage;
                OnPropertyChanged(nameof(StatusMessage));
            }
        }
コード例 #9
0
        public static ILogger HandleLogging(this ILogger logger, LoggingModel logginModel)
        {
            if (logginModel == null)
            {
                return(logger);
            }

            logger = logger
                     .ForContext(nameof(logginModel.RequestHost), logginModel.RequestHost)
                     .ForContext(nameof(logginModel.RequestProtocol), logginModel.RequestProtocol)
                     .ForContext(nameof(logginModel.RequestMethod), logginModel.RequestMethod)
                     .ForContext(nameof(logginModel.ResponseStatusCode), logginModel.ResponseStatusCode)
                     .ForContext(nameof(logginModel.RequestPath), logginModel.RequestPath)
                     .ForContext(nameof(logginModel.RequestPathAndQuery), logginModel.RequestPathAndQuery);

            if (logginModel.RequestHeaders != null && logginModel.RequestHeaders.Any())
            {
                logger = logger.ForContext(nameof(logginModel.RequestHeaders), logginModel.RequestHeaders, true);
            }

            if (logginModel.ElapsedMilliseconds != null)
            {
                logger = logger.ForContext(nameof(logginModel.ElapsedMilliseconds), logginModel.ElapsedMilliseconds);
            }

            if (!string.IsNullOrEmpty(logginModel.RequestBody))
            {
                logger = logger.ForContext(nameof(logginModel.RequestBody), logginModel.RequestBody);
            }

            if (logginModel.Exception != null)
            {
                logger = logger.ForContext(nameof(logginModel.Exception), logginModel.Exception, true);
            }

            if (!string.IsNullOrEmpty(logginModel.Data))
            {
                logger = logger.ForContext(nameof(logginModel.Data), logginModel.Data);
            }

            return(logger);
        }
コード例 #10
0
        private static async Task InternalServerError(HttpContext context, Exception exception, string data, string contentType = "text/plain")
        {
            await Task.Run(() =>
            {
                var request             = context.Request;
                var encodedPathAndQuery = request.GetEncodedPathAndQuery();

                var logModel = new LoggingModel(request.Host.Host, request.Protocol, request.Method, request.Path, encodedPathAndQuery, StatusCodes.Status500InternalServerError)
                {
                    RequestHeaders = request.Headers.ToDictionary(x => x.Key, x => (object)x.Value.ToString()),
                    RequestBody    = string.Empty,
                    Exception      = exception,
                    Data           = data
                };

                Logger.HandleLogging(logModel).Error(LogTemplates.Error);
            });

            context.Response.Clear();
            context.Response.ContentType = contentType;
            context.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            context.Response.StatusCode = StatusCodes.Status500InternalServerError;
            await context.Response.WriteAsync("Sunucuda beklenmeyen bir hata oluştu.", Encoding.UTF8);
        }
コード例 #11
0
        public static LoggingModel GetLog(HttpContext context)
        {
            string reqPath        = context.Request.Path.ToString();
            string reqQueryString = context.Request.QueryString.ToString();

            //客户端信息
            var ct = new ClientTo(context);

            //用户信息
            var userinfo = LoginService.Get(context);

            //日志保存
            var mo = new LoggingModel()
            {
                LogApp        = GlobalTo.GetValue("Common:EnglishName"),
                LogUid        = userinfo?.UserName,
                LogNickname   = userinfo?.Nickname,
                LogAction     = reqPath,
                LogUrl        = reqPath + reqQueryString,
                LogIp         = ct.IPv4,
                LogReferer    = ct.Referer,
                LogCreateTime = DateTime.Now,
                LogUserAgent  = ct.UserAgent,
                LogGroup      = "1",
                LogLevel      = "I"
            };

            var ddk = reqPath.ToLower().TrimStart('/');

            if (DicDescription.ContainsKey(ddk))
            {
                mo.LogContent = DicDescription[ddk];
            }

            return(mo);
        }
コード例 #12
0
        public async Task <IActionResult> Post([FromBody] LoggingModel logModel)
        {
            var response = await _loggerService.LogAsync(logModel);

            return(StatusCode(StatusCodes.Status200OK, response));
        }
コード例 #13
0
        public LoggingModel GetApplicationLogs(String appName, String logLevel, int top, int skip, String search = "")
        {
            var result = new LoggingModel();

            // Create a SQL command to execute the sproc
            using (SqlCommand command = (SqlCommand)StoreDbContext.Database.Connection.CreateCommand())
            {
                command.CommandTimeout = StoreConstants.StoreProcedureCommandTimeOut;
                command.CommandType    = CommandType.StoredProcedure;
                command.CommandText    = "log_GetApplicationLogs";
                if (!String.IsNullOrEmpty(appName.Trim()))
                {
                    command.Parameters.Add("AppName", SqlDbType.NVarChar).Value = appName;
                }
                else
                {
                    command.Parameters.Add("AppName", SqlDbType.NVarChar).Value = DBNull.Value;
                }

                if (!String.IsNullOrEmpty(search.Trim()))
                {
                    command.Parameters.Add("search", SqlDbType.NVarChar).Value = search;
                }
                else
                {
                    command.Parameters.Add("search", SqlDbType.NVarChar).Value = DBNull.Value;
                }

                if (!String.IsNullOrEmpty(logLevel.Trim()))
                {
                    command.Parameters.Add("logLevel", SqlDbType.NVarChar).Value = logLevel;
                }
                else
                {
                    command.Parameters.Add("logLevel", SqlDbType.NVarChar).Value = DBNull.Value;
                }

                command.Parameters.Add("top", SqlDbType.Int).Value  = top;
                command.Parameters.Add("skip", SqlDbType.Int).Value = skip;


                using (SqlDataAdapter adapter = new SqlDataAdapter())
                {
                    adapter.SelectCommand = command;

                    using (DataSet dataset = new DataSet())
                    {
                        adapter.Fill(dataset);

                        var systemLoggingList = new List <system_logging>();
                        using (DataTable dt = dataset.Tables[0])
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                var systemLogging = new system_logging();
                                systemLogging.entered_date    = dr["entered_date"].ToDateTime();
                                systemLogging.log_application = dr["log_application"].ToStr();
                                systemLogging.log_date        = dr["log_date"].ToStr();
                                systemLogging.log_level       = dr["log_level"].ToStr();
                                systemLogging.log_logger      = dr["log_logger"].ToStr();
                                systemLogging.log_message     = dr["log_message"].ToStr();
                                systemLogging.log_call_site   = dr["log_call_site"].ToStr();
                                systemLogging.log_exception   = dr["log_exception"].ToStr();
                                systemLogging.log_stacktrace  = dr["log_stacktrace"].ToStr();
                                systemLoggingList.Add(systemLogging);
                            }
                        }

                        result.SystemLoggingList = systemLoggingList;

                        RecordsStats stats = new RecordsStats();
                        using (DataTable dt = dataset.Tables[1])
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                stats.RecordFirst  = dr["RecordFirst"].ToInt();
                                stats.RecordLast   = dr["RecordLast"].ToInt();
                                stats.RecordsTotal = dr["RecordsTotal"].ToInt();
                                stats.RecordCount  = dr["recordCount"].ToInt();
                            }
                        }
                        result.RecordsStats = stats;
                    } // dataset
                }     //dataAdapter
            }         //command

            return(result);
        }
コード例 #14
0
        public ActionResult Post([FromBody] LoggingModel loggingModel)
        {
            logger.Log(ConvertToLogLevel(loggingModel.Level), string.Format("[{0}] {1}", loggingModel.ServiceName, loggingModel.Message));

            return(Ok());
        }