in src/Microsoft.IIS.Administration.WebServer.Logging/LoggingHelper.cs [31:154]
internal static object ToJsonModel(Site site, string path)
{
LogSection logSection = GetLogSection(site, path);
HttpLoggingSection httpLogSection = GetHttpLoggingSection(site, path);
SiteLogFile logFile = null;
if (site == null) {
logFile = ManagementUnit.Current.ServerManager.SiteDefaults.LogFile;
}
else {
logFile = site.LogFile;
}
LoggingId id = new LoggingId(site?.Id, path, httpLogSection.IsLocallyStored);
Dictionary<string, bool> logTargetW3C = new Dictionary<string, bool>();
if (logFile.Schema.HasAttribute(LogTargetW3CAttribute)) {
LogTargetW3C target = logFile.LogTargetW3C;
logTargetW3C.Add("etw", target.HasFlag(LogTargetW3C.ETW));
logTargetW3C.Add("file", target.HasFlag(LogTargetW3C.File));
}
FileLogFormat logFormat;
if (logSection.CentralLogFileMode == CentralLogFileMode.Site) {
logFormat = FromLogFormat(logFile.LogFormat);
}
else {
logFormat = logSection.CentralLogFileMode == CentralLogFileMode.CentralBinary ? FileLogFormat.Binary : FileLogFormat.W3c;
}
bool logFilePerSite = logSection.CentralLogFileMode == CentralLogFileMode.Site;
string directory = default(string);
string period = default(string);
long truncateSize = default(long);
bool useLocalTime = default(bool);
Dictionary<string, bool> logTargetW3c = default(Dictionary<string, bool>);
Dictionary<string, bool> logFields = default(Dictionary<string, bool>);
IEnumerable<object> customLogFields = default(IEnumerable<object>);
switch(logSection.CentralLogFileMode) {
case CentralLogFileMode.CentralBinary:
directory = logSection.CentralBinaryLogFile.Directory;
period = PeriodRepresentation(logSection.CentralBinaryLogFile.Period);
truncateSize = logSection.CentralBinaryLogFile.TruncateSize;
useLocalTime = logSection.CentralBinaryLogFile.LocalTimeRollover;
logTargetW3c = null;
logFields = null;
customLogFields = null;
break;
case CentralLogFileMode.CentralW3C:
directory = logSection.CentralW3CLogFile.Directory;
period = PeriodRepresentation(logSection.CentralW3CLogFile.Period);
truncateSize = logSection.CentralW3CLogFile.TruncateSize;
useLocalTime = logSection.CentralW3CLogFile.LocalTimeRollover;
logTargetW3c = null;
logFields = LogExtFileFlagsRepresentation(logSection.CentralW3CLogFile.LogExtFileFlags);
customLogFields = null;
break;
case CentralLogFileMode.Site:
directory = logFile.Directory;
period = PeriodRepresentation(logFile.Period);
truncateSize = logFile.TruncateSize;
useLocalTime = logFile.LocalTimeRollover;
logTargetW3c = logTargetW3C;
logFields = LogExtFileFlagsRepresentation(logFile.LogExtFileFlags);
if (logFile.Schema.HasChildElement(CustomFieldsElement)) {
customLogFields = logFile.CustomLogFields.Select(custField => {
return new
{
field_name = custField.LogFieldName,
source_name = custField.SourceName,
source_type = SourceTypeRepresentation(custField.SourceType)
};
});
}
break;
}
dynamic o = new ExpandoObject();
o.id = id.Uuid;
o.scope = site == null ? string.Empty : site.Name + path;
// The metadata is obtained solely from <httpLogSection> because the <log> section is in applicationHost/* path which means it can't be accessed in web configs
o.metadata = ConfigurationUtility.MetadataToJson(httpLogSection.IsLocallyStored, httpLogSection.IsLocked, httpLogSection.OverrideMode, httpLogSection.OverrideModeEffective);
o.enabled = IsLoggingEnabled(httpLogSection, logSection, logFile);
o.log_per_site = logFilePerSite;
o.directory = directory;
o.log_file_encoding = logSection.LogInUTF8 ? "utf-8" : "ansi";
o.log_file_format = Enum.GetName(typeof(FileLogFormat), logFormat).ToLower();
if (logFile.Schema.HasAttribute(LogTargetW3CAttribute)) {
o.log_target = logTargetW3c;
}
o.log_fields = logFields;
if (logFile.Schema.HasChildElement(CustomFieldsElement)) {
o.custom_log_fields = customLogFields;
}
o.rollover = new {
period = period,
truncate_size = truncateSize,
use_local_time = useLocalTime,
};
o.website = SiteHelper.ToJsonModelRef(site);
return Core.Environment.Hal.Apply(Defines.Resource.Guid, o);
}