我怎样才能登录Windows Azure中(MVC)的错误和用户操作? [英] How can I log errors and user actions in Windows Azure (MVC)?
问题描述
Azure的变化如此之快,因此可能有人给我我怎么可能会登录一些建议:
Azure is changing so quickly so could someone give me some suggestions on how could I could log:
- 错误
- 例外
- 用户操作
我希望能够把这些记录到表存储,使他们能够与code进行检索和行政浏览过的网页。我不是在寻找这么多的code,但我真正想要的是要知道我应该看看。 Azure的变化如此之快我想一定要使用什么是最好的。
I would like to be able to log these to table storage so they can be retrieved with code and viewed on administrative web pages. I am not looking so much for code but what I really want is to know where I should look. Azure changes so fast I want to be sure to use what's best.
感谢您
推荐答案
我只是做了上周末类似的东西。最后我只是创造1台名为LOGEVENTS和所用的关键供应商分出不同类型的日志事件和日期(例如ProviderKey =20111121_LoginEvent当有人登录在11月21日)。
I just did something similar on the weekend. I ended up just creating 1 table called "LogEvents" and used the provider key to separate the different types of log events and dates (e.g. the ProviderKey = "20111121_LoginEvent" when someone logged in on 21 Nov).
有关我的查询然后可以很容易地对日期/类型来完成和管理员页面上显示的结果。
For me the queries can then be done quite easily on date/type and display the result on an admin page
不知道这是最好的方式,但它似乎是为我工作。我没有搜索谷歌,但找不到任何东西,真的这样做。
Not sure if this is the best way but it seems to be working for me. I did search Google but couldn't find anything that really did this.
更新1:
我使用的类名为LogEvent可以:
Update 1: The class I use is called LogEvent:
public class LogEntry : TableServiceEntity
{
public LogEntry(string logType)
{
if (LogType == null || LogType.Length == 0)
{
if (logType.Length > 0)
LogType = logType;
else
LogType = "Default";
}
PartitionKey = string.Format("{0}_{1}", LogType, DateTime.UtcNow.ToString("yyyyMMdd"));
RowKey = string.Format("{0:10}_{1}", DateTime.MaxValue.Ticks - DateTime.Now.Ticks, Guid.NewGuid());
}
public LogEntry()
{
}
public string Message { get; set; }
public DateTime LogDateTime { get; set; }
public string LogType { get; set; }
}
我刚刚创建它的一个新的实例并设置属性:
I just create a new instance of it and set the properties:
LogEntry le = new LogEntry("Default") { Message = "Default Page Loaded", LogDateTime=DateTime.Now };
LogEntryDataSource ds = new LogEntryDataSource();
ds.AddLogEntry(le);
要背出来再次获取数据我只是用一个标准的Linq查询和传递日期和LOGTYPE:
To get the data back out again I just use a standard Linq query and pass in the date and LogType:
public IEnumerable<LogEntry> GetLogEntries(string eventType, DateTime logDate)
{
var results = from g in this.context.LogEntry
where g.PartitionKey == String.Format("{0}_{1}", eventType, logDate.ToString("yyyyMMdd"))
select g;
return results;
}
有可能是一个更好的办法,但是,这是pretty简单的设置,它的工作对我来说
There's probably a better way but this was pretty simple to setup and it's working for me
这篇关于我怎样才能登录Windows Azure中(MVC)的错误和用户操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!