當前位置: 首頁>>代碼示例>>C#>>正文


C# Log.Save方法代碼示例

本文整理匯總了C#中System.Log.Save方法的典型用法代碼示例。如果您正苦於以下問題:C# Log.Save方法的具體用法?C# Log.Save怎麽用?C# Log.Save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Log的用法示例。


在下文中一共展示了Log.Save方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: OnActionExecuting

        /// <summary>
        /// 檢查用戶是否有該Action執行的操作權限
        /// </summary>
        /// <param name="actionContext"></param>
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            //增加操作日誌
            var log = new Log()
            {
                Action = $"{actionContext.ControllerContext.ControllerDescriptor.ControllerName}/{actionContext.ActionDescriptor.ActionName}",
                Note = GetText(actionContext.ActionArguments)
            };

            var b = actionContext.Request.Headers.Referrer;
            var attr = actionContext.ActionDescriptor.GetCustomAttributes<AllowAnonymousAttribute>();
            if (attr.Any(a => a != null))//判斷是否允許匿名調用
            {
                base.OnActionExecuting(actionContext);
            }
            else if (b != null && CfgLoader.Instance.GetArraryConfig<string>("Csrf", "Address").Any(r => b.ToString().StartsWith(r)))
            {
                AuthFrom(actionContext, ref log);
            }
            else if (b == null)
            {
                actionContext.Response = new HttpResponseMessage(HttpStatusCode.Unauthorized);
            }

            base.OnActionExecuting(actionContext);

            log.Save(Guid.Empty);
        }
開發者ID:thornfieldhe,項目名稱:TAF,代碼行數:32,代碼來源:AuthenticationFilterAttribute.cs

示例2: LogException

        /// <summary>
        /// Logs an exception
        /// </summary>
        /// <param name="msg">Descriptive message</param>
        /// <param name="ex">Current exception</param>
        /// <param name="authName">Current users authentication name</param>
        /// <param name="errorType">Error type</param>
        /// <returns>bool Success</returns>
        private static bool LogException(string msg, Exception ex, LogMessageType errorType, string authName)
        {
            bool Success = true;
              try {
            string exMessage = string.Empty;
            string exType = string.Empty;
            StringBuilder exSource = new StringBuilder();
            string exStackTrace = string.Empty;
            string scriptName;
            string userAgent = string.Empty;
            string referer = string.Empty;
            string remoteHost = string.Empty;
            string authUser = authName;
            string formData = string.Empty;
            string queryStringData = string.Empty;
            string cookiesData = string.Empty;

            if (ex != null) {
              while (ex != null) {
            if (ex.InnerException == null) {
              exMessage = ex.Message;
              exType = ex.GetType().ToString();
              exStackTrace = ex.StackTrace;
            }
            exSource.Append("[");
            exSource.Append(ex.Source);
            exSource.Append("]");

            ex = ex.InnerException;
              }
            }

            // Leave all HTTP-specific information out if this
            // method is being called from a Win/Console app.
            if (HttpContext.Current == null)
              scriptName = Environment.CommandLine;
            else {
              HttpContext thisContext = HttpContext.Current;
              HttpRequest thisRequest = thisContext.Request;

              scriptName = thisRequest.CurrentExecutionFilePath;
              userAgent = thisRequest.ServerVariables["HTTP_USER_AGENT"];
              referer = thisRequest.ServerVariables["HTTP_REFERER"];
              remoteHost = thisRequest.ServerVariables["HTTP_X_FORWARDED_FOR"];
              if (string.IsNullOrEmpty(remoteHost))
            remoteHost = thisRequest.ServerVariables["REMOTE_HOST"];
              authUser = thisRequest.ServerVariables["AUTH_USER"];
              formData = thisRequest.Form.ToString();
              queryStringData = thisRequest.QueryString.ToString();
              cookiesData = GetCookiesAsString(thisContext);
            }

            Log log = new Log();
            log.AuthUser = authUser;
            log.Referer = referer;
            log.RemoteHost = remoteHost;
            log.Message = msg ?? string.Empty;
            log.UserAgent = userAgent;
            log.ScriptName = scriptName;
            log.ExceptionMessage = exMessage;
            log.ExceptionSource = exSource.ToString();
            log.ExceptionStackTrace = exStackTrace;
            log.MachineName = Environment.MachineName;
            log.ExceptionType = exType;
            log.MessageType = (byte)errorType;
            log.CookiesData = cookiesData;
            log.FormData = formData;
            log.QueryStringData = queryStringData;
            log.LogDate = DateTime.UtcNow;
            log.Save();
              }
              catch {
            Success = false;
              }
              return Success;
        }
開發者ID:freecin,項目名稱:dashcommerce-3,代碼行數:84,代碼來源:Logger.cs


注:本文中的System.Log.Save方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。