【Azure 云服务】Azure Cloud Service 为 Web Role(IIS Host)增加自定义字段 (把HTTP Request Header中的User-Agent字段增加到IIS输出日志中)
问题描述
把Web Role服务发布到Azure Cloud Service后,需要在IIS的输出日志中,把每一个请求的HTTP Request Header中的User-Agent内容也输出到日志中。通过Cloud Service(云服务)如何实现呢?
解决方案
方案一(临时):Cloud Service WebRole是Host在IIS中,所以可以通过对IIS的Logging设置就可以(RDP到VM中修改)
1:RDP到云服务的实例上,搜索IIS Manager
2:打开之后,找到云服务实例,点击Logging。 如下截图所示:
3:打开之后,在Log File 里面的Format 选择W3C ,点击Select Fields,进行添加自定义字段
4:修改完成后,新生成的IIS日志中就会包含列名为UUID,内容为User-Agent的内容。
方案二:通过Cloud Service的启动任务对IIS Logging进行设置(需重新部署一次云服务)
1:在Cloud Service中设置启动任务,在WebRole项目的ServiceDefinition.csdef文件中加入 Startup 内容:
<Startup> <Task commandLine="Startup.cmd" executionContext="limited" taskType="simple" > <Environment> <Variable name="MyVersionNumber" value="1.0.0.0" /> </Environment> </Task> </Startup>
2: 在项目根目录中添加文件 Startup.cmd,文件内容为:
d /d "%~dp0" %windir%\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/sites /+"siteDefaults.logFile.customFields.[logFieldName='UUID',sourceName='User-Agent',sourceType='RequestHeader']" /commit:apphost >> "%TEMP%\StartupLog.txt" 2>&1 exit /b 0ad8
PS: 通过修改IIS config的方式来配置Loggin中的自定义日志字段
3: 重新部署整个Cloud Service,即可生效。
参考资料
如何配置和运行 Azure 云服务(经典)的启动任务:https://docs.microsoft.com/zh-cn/azure/cloud-services/cloud-services-startup-tasks#example-of-a-startup-task
Adding Custom Fields to a Log File for a Site <add> : https://docs.microsoft.com/en-us/iis/configuration/system.applicationhost/sites/site/logfile/customfields/add#sample-code
如何在部署云服务Cloud Service时候通过启动任务Start Task来配置IIS (如开启ARR) : https://www.cnblogs.com/lulight/p/13579629.html
- Windows Azure Cloud Service (22) Web Role的Full IIS特性
- Web service request SetParameters to Report Server http://host/reportserver failed. Error: 请求因 HTTP 状态 401 失败: Unauthorized
- 【Azure 应用服务】App Service .NET Core项目在Program.cs中自定义添加的logger.LogInformation,部署到App Service上后日志不显示Log Stream中的问题
- Windows Azure Cloud Service (41) 修改云服务IIS托管管道模式为4.0经典模式
- windows azure Vm、cloud service、web application 如何选择可用的服务
- Windows Azure Cloud Service (11) PaaS之Web Role, Worker Role(上)
- Web service request SetParameters to Report Server http://host/reportserver failed. Error: 请求因 HTTP 状态 401 失败: Unauthorized
- asp.net web api的自托管模式HttpSelfHostServer可以以控制台程序或windows服务程序为宿主,不单单依赖于IIS web服务器
- Web service request SetParameters to Report Server http://host/reportserver failed. Error: 请求因 HTTP 状态 401 失败: Unauthorized
- [New Portal]Windows Azure Web Site (5) 如何选择Windows Azure托管服务的类型?WebSite, Cloud Service还是Virtual Machine
- 【Azure 应用服务】App Service 通过配置web.config来添加请求返回的响应头(Response Header)
- 关于”System.ServiceModel.Activation.WebServiceHostFactory“与"<webHttp/>"以及RestFul/启用了Ajax的WCF服务
- Windows Azure Cloud Service (12) PaaS之Web Role, Worker Role, Azure Storage Queue(下)
- Web service request SetParameters to Report Server http://host/reportserver failed. Error: 请求因 HTTP 状态 401 失败: Unauthorized
- nginx日志输出自定义header头字段
- java.lang.IllegalStateException: Request URI does not contain a valid hostname: http://user_service/
- HttpWebRequest.UserAgent 浏览器USER_AGENT留存
- 使用HttpWebRequest发送自定义POST请求
- 背水一战 Windows 10 (64) - 控件(WebView): 加载指定 HttpMethod 的请求, 自定义请求的 http header, app 与 js 的交互
- SD--如何在输出控制中增加自定义字段