Tracing provider wrapper can use to audit.

Jul 29, 2012 at 6:16 AM

First thanks for this great tool and the author of this good topic. Thanks again.

LogAction is a perfect delegate function to write all executed or executing sql to audit log file.

protected void Application_Start()

        EFTracingProviderConfiguration.LogAction = LogCommandExecution;
 }


        void LogCommandExecution(CommandExecutionEventArgs e)

            StringBuilder sb = new StringBuilder();
            string user = "Anonymous User";
            if (HttpContext.Current != null)
            { 
              user = string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name) 
                  ? "Anonymous User from web app"
                  : HttpContext.Current.User.Identity.Name + ": " 
                  + HttpContext.Current.User.Identity.AuthenticationType + ": "
                  + HttpContext.Current.User.Identity.IsAuthenticated.ToString();
           }
            sb.AppendLine(user);
            sb.AppendLine(e.Status.ToString());
            sb.AppendLine(e.ToTraceString());
            Logger.Write(sb.ToString());
       }