0
A
回答
1
有什么办法可以保存到SQL数据库吗?
Azure Web App目前不提供此功能。您可以在以下站点发布功能请求。
How can we improve Azure Web Apps?
Web服务器日志使用W3C日志记录格式。如果我们选择将此日志保存到存储的选项。登录Azure的Blob服务的文件名格式都是这样的,
[ServerLogContainerName]>[WebAppName]>[Year]>[Month]>[Day]>[Hour]>[LogFileName].log
Azure的Web应用程序将保存时间纪录群组。我们可以创建WebJob并使用TimeTrigger读取日志,解析日志文件并将数据每小时保存到SQL Server。以下代码供您参考。
// Runs immediately on startup, then every two hour
public static void SaveLogsToSQLJob(
[TimerTrigger("0 0 * * * *", RunOnStartup = true)] TimerInfo timerInfo)
{
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("connection_string");
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("ServerLogContainerName");
var blobs = container.GetDirectoryReference("YourWebAppName").GetDirectoryReference(DateTime.Now.Year.ToString())
.GetDirectoryReference(DateTime.Now.Month.ToString())
.GetDirectoryReference((DateTime.Now.Hour == 0 ? DateTime.Now.Day - 1 : DateTime.Now.Day).ToString())
.GetDirectoryReference((DateTime.Now.Hour == 0 ? 23 : DateTime.Now.Hour - 1).ToString()).ListBlobs();
foreach (CloudBlockBlob blob in blobs)
{
using (Stream stream = blob.OpenRead())
{
using (StreamReader sr = new StreamReader(stream))
{
string line = null;
while ((line = sr.ReadLine()) != null)
{
if (!line.StartsWith("#"))
{
string[] fields = line.Split(' ');
//Save these fields to database
}
}
}
}
}
}
根据日志文件,我们需要在SQL表中创建以下16列。
date time s-sitename cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Cookie) cs(Referer) cs-host sc-status sc-substatus sc-win32-status
相关问题
- 1. 登录到服务器时未登录到服务器
- 2. 服务器到服务器Web服务
- 3. 从Iphone App登录到Web服务器?
- 4. 登录到SharePoint Web服务使用一个非FBA服务器
- 5. Microsoft SQL Server IP /服务器登录
- 6. 无法登录到SQL服务器
- 7. SQL链接服务器登录错误
- 8. 无法登录SQL服务器
- 9. SQL服务器 - 用户'登录失败。
- 10. 登录到PHP服务器
- 11. 登录谷歌服务器
- 12. 无法使用Azure平台登录到SQL服务器
- 13. Web服务的服务器
- 14. Web服务TCP服务器
- 15. SQL服务器 - >的Sybase
- 16. Apache - >代理服务器和Web服务器
- 17. Web服务器
- 18. web服务器vs部署服务器
- 19. 部署SyncFusion报表服务器IIS服务器登录提示
- 20. 从服务器到服务器的持久登录信息
- 21. Amazon EC2服务器 - 具有根权限的登录服务器
- 22. SQL服务器根目录
- 23. 上传日期在web服务器在sql服务器
- 24. App> OAuth2服务器> Facebook> OAuth2服务器> App
- 25. 在SANDBY服务器上登录新Sql登录
- 26. SQL服务器:链接服务器没有链接服务器?
- 27. SQL服务器
- 28. SQL服务器
- 29. SQL服务器
- 30. SQL(服务器):