FTP 中央日志记录选项 <centralLogFile>
概述
<centralLogFile>
元素指定中央日志文件的设置,在为 <system.ftpServer/log>
元素的 centralLogFileMode
属性指定 centralLogFileMode 时会使用此文件。 指定中央日志记录时,将在单个日志文件中保存所有 FTP 站点的日志。
兼容性
版本 | 说明 |
---|---|
IIS 10.0 | <centralLogFile> 元素在 IIS 10.0 中未进行修改。 |
IIS 8.5 | <centralLogFile> 元素在 IIS 8.5 中未进行修改。 |
IIS 8.0 | <centralLogFile> 元素在 IIS 8.0 中未进行修改。 |
IIS 7.5 | <log> 元素的 <centralLogFile> 元素作为 IIS 7.5 的功能提供。 |
IIS 7.0 | <log> 元素的 <centralLogFile> 元素是在 IIS 7.0 的独立下载项 FTP 7.0 中引入的。 |
IIS 6.0 | <system.ftpServer> 元素及其子元素替换位于 LM/MSFTPSVC 元数据库路径中的 IIS 6.0 FTP 设置。 |
在 Windows 7 和 Windows Server 2008 R2 中,FTP 7.5 服务作为 IIS 7.5 的功能提供,因此无需再下载 FTP 服务。
安装
若要支持 Web 服务器的 FTP 发布,必须安装 FTP 服务。 为此,请按照以下步骤操作。
Windows Server 2012 或 Windows Server 2012 R2
在任务栏上,单击 “服务器管理器”。
在“服务器管理器”中,单击“管理”菜单,然后单击“添加角色和功能”。
在“添加角色和功能”向导中,单击“下一步”。 选择安装类型,然后单击“下一步”。 选择目标服务器,然后单击“下一步”。
在“服务器角色”页上,展开“Web 服务器 (IIS)”,然后选择“FTP 服务器”。
单击“下一步”,然后在“选择功能”页上,再次单击“下一步”。
在“确认安装选择”页上,单击“安装”。
在“结果” 页面中单击“关闭” 。
Windows 8 或 Windows 8.1
在“开始”屏幕上,将指针一直移动到左下角,右键单击“开始”按钮,然后单击“控制面板”。
在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
展开“Internet Information Services”,然后选择“FTP 服务器”。
单击“确定”。
单击“关闭” 。
Windows Server 2008 R2
在任务栏上,单击“开始”,指向“管理工具”,然后单击“服务器管理器”。
在“服务器管理器”层次结构窗格中,展开“角色”,然后单击“Web 服务器(IIS)”。
在“Web 服务器 (IIS)”窗格中,滚动到“角色服务”部分,然后单击“添加角色服务”。
在“添加角色服务向导”的“选择角色服务”页,展开“FTP 服务器”。
选择“FTP 服务”。
单击 “下一步” 。
在“确认安装选择”页中,单击“安装”。
在“结果” 页面中单击“关闭” 。
Windows 7
在任务栏上,单击“开始”,然后单击“控制面板”。
在“控制面板”中,单击“程序与功能”,然后单击“打开或关闭 Windows 功能”。
展开“Internet Information Services”,然后展开“FTP 服务器”。
选择“FTP 服务”。
单击“确定”。
Windows Server 2008 或 Windows Vista
从以下 URL 下载安装包:
按照以下演练中的说明安装 FTP 服务:
操作方式
如何为 FTP 服务配置站点级或服务器级日志记录
打开 Internet Information Services (IIS) 管理器:
如果使用的是 Windows Server 2012 或 Windows Server 2012 R2:
- 在任务栏上,单击“服务器管理器”,单击“工具”,然后单击“Internet Information Services (IIS)管理器”。
如果使用的是 Windows 8 或 Windows 8.1:
- 按住 Windows 键,按字母 X,然后单击“控制面板”。
- 单击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
如果使用的是 Windows Server 2008 或 Windows Server 2008 R2:
- 在任务栏上,单击“开始”,指向“管理工具”,然后单击“Internet Information Services (IIS)管理器”。
如果使用的是 Windows Vista 或 Windows 7:
- 在任务栏上,单击“开始”,然后单击“控制面板”。
- 双击“管理工具”,然后双击“Internet 信息服务(IIS)管理器”。
在“连接”窗格中,单击服务器名称。
在“一个日志文件/每”下拉列表中选择以下选项之一:
在“操作”窗格中,单击“应用”。
配置
<centralLogFile>
元素在 ApplicationHost.config 中的全局级别配置。
属性 | 说明 | ||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
directory |
可选的字符串属性。 指定日志记录目录,其中存储日志文件和与日志记录相关的支持文件。 默认值为 %SystemDrive%\inetpub\logs\LogFiles 。 |
||||||||||||||||||||||||||||||||||||||||||||
enabled |
可选的 Boolean 属性。 如果启用了日志记录,则为 true;否则为 false。 默认值为 true 。 |
||||||||||||||||||||||||||||||||||||||||||||
localTimeRollover |
可选的 Boolean 属性。 如果基于本地时间创建新日志文件,则为 true;否则,基于协调世界时 (UTC)(以前称为格林威治标准时间 (GMT))创建则为 false。 注意:无论设置如何,每个 W3C 扩展日志记录的时间戳都是基于 UTC 的。 默认值为 false 。 |
||||||||||||||||||||||||||||||||||||||||||||
logExtFileFlags |
可选 flags 属性。 指定在记录站点事件期间写入日志文件(使用 W3C 扩展日志文件格式时)或 ODBC 数据源的信息类别。 logExtFileFlags 属性可为以下一个或多个值。 如果指定多个值,请用逗号 (,) 分隔。 默认值为 Date 、Time 、ClientIP 、UserName 、ServerIP 、Method 、UriStem 、FtpStatus 、Win32Status 、FtpSubStatus 、ServerPort 、Session 和 FullPath 。
|
||||||||||||||||||||||||||||||||||||||||||||
period |
可选的枚举属性。 指定 FTP 服务创建新日志文件的频率。 period 属性可为以下值之一。默认值为 Daily 。
|
||||||||||||||||||||||||||||||||||||||||||||
selectiveLogging |
可选 flags 属性。 指定 FTP 日志记录的详细程度。 默认值为 LogSuccessful,LogError,LogInfrastructure 。
|
||||||||||||||||||||||||||||||||||||||||||||
truncateSize |
可选 int64 属性。 指定日志文件的最大大小(以字节为单位),超过该大小后将创建新日志文件。 仅当为 period 属性选择了 MaxSize 时,此值才适用。 最小文件大小是 1,048,576 字节。 如果将此特性设置为小于 1048576 个字节的值,则会隐式将默认值假定为 1048576 个字节。默认值为 20971520 。 |
子元素
无。
配置示例
以下配置示例为 FTP 服务启用中央文件日志记录。
<system.ftpServer>
<log centralLogFileMode="Central">
<centralLogFile enabled="true" />
</log>
</system.ftpServer>
代码示例
以下示例为 FTP 服务启用中央文件日志记录。
AppCmd.exe
appcmd.exe set config -section:system.ftpServer/log /centralLogFileMode:"Central" /commit:apphost
appcmd.exe set config -section:system.ftpServer/log /centralLogFile.enabled:"True" /commit:apphost
注意
使用 AppCmd.exe 配置这些设置时,必须确保将 commit 参数设置为 apphost
。 这会将配置设置提交到 ApplicationHost.config 文件中的相应位置部分。
C#
using System;
using System.Text;
using Microsoft.Web.Administration;
internal static class Sample
{
private static void Main()
{
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection logSection = config.GetSection("system.ftpServer/log");
logSection["centralLogFileMode"] = @"Central";
ConfigurationElement centralLogFileElement = logSection.GetChildElement("centralLogFile");
centralLogFileElement["enabled"] = true;
serverManager.CommitChanges();
}
}
}
VB.NET
Imports System
Imports System.Text
Imports Microsoft.Web.Administration
Module Sample
Sub Main()
Dim serverManager As ServerManager = New ServerManager
Dim config As Configuration = serverManager.GetApplicationHostConfiguration
Dim logSection As ConfigurationSection = config.GetSection("system.ftpServer/log")
logSection("centralLogFileMode") = "Central"
Dim centralLogFileElement As ConfigurationElement = logSection.GetChildElement("centralLogFile")
centralLogFileElement("enabled") = True
serverManager.CommitChanges()
End Sub
End Module
JavaScript
var adminManager = new ActiveXObject('Microsoft.ApplicationHost.WritableAdminManager');
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST";
var logSection = adminManager.GetAdminSection("system.ftpServer/log", "MACHINE/WEBROOT/APPHOST");
logSection.Properties.Item("centralLogFileMode").Value = "Central";
var centralLogFileElement = logSection.ChildElements.Item("centralLogFile");
centralLogFileElement.Properties.Item("enabled").Value = true;
adminManager.CommitChanges();
VBScript
Set adminManager = createObject("Microsoft.ApplicationHost.WritableAdminManager")
adminManager.CommitPath = "MACHINE/WEBROOT/APPHOST"
Set logSection = adminManager.GetAdminSection("system.ftpServer/log", "MACHINE/WEBROOT/APPHOST")
logSection.Properties.Item("centralLogFileMode").Value = "Central"
Set centralLogFileElement = logSection.ChildElements.Item("centralLogFile")
centralLogFileElement.Properties.Item("enabled").Value = True
adminManager.CommitChanges()