csharp Sql Log 1 Mvc

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Sql Log 1 Mvc相关的知识,希望对你有一定的参考价值。

public static int getDbCommandTimeOut()
{
	int value = 0;
	if (!int.TryParse(System.Web.Configuration.WebConfigurationManager.AppSettings["CommandTimeout"], out value))
	value = 120;
	return value;
}

public static async Task StoreSqlLog(String UserName, String sql)
{
	string _userName = UserName ?? HttpContext.Current.Request.Headers.Get("V69DLOSn2KiWZQ23GKBZ");
	String user = (String.IsNullOrEmpty(_userName) ? HttpContext.Current.User.Identity.GetUserId() : GetUserByName(_userName).Id) ?? ("98947c8e-e209-4bf7-b970-5e1343602922");

	String text = HttpContext.Current.Request.Url.Host.ToLower();
	if (!HttpContext.Current.Request.Url.Host.ToLower().Equals("localhost"))
	{
		String ip = HttpContext.Current.Request.UserHostAddress;
		using (var dbc = new DataEntities())
		{
			SQLLog log = new SQLLog()
			{
				SQLLogIP = ip + "/M",
				SQLLogSQLKodu = sql,
				SQLLogTarih = DateTime.Now,
				SQLLogUserID = user
			};
			dbc.SQLLogs.Add(log);
			await dbc.SaveChangesAsync();
		}
	}
}

context.Database.CommandTimeout = Storage.getDbCommandTimeOut();
string sql = ;
await Storage.StoreSqlLog(null, sql);

以上是关于csharp Sql Log 1 Mvc的主要内容,如果未能解决你的问题,请参考以下文章

csharp AJAX GET MVC

csharp MVC模型上的日期格式

csharp 排序,分页,过滤Paging.mvc

csharp 单元测试MVC JsonResult对象

csharp ASP.NET MVC 5表单

csharp 在MVC中下载文件