I am hosting the test website in IIS . and configured W3C logging with custom field . config for my Testing site is
XML
<site name="Testing" id="8" serverAutoStart="true">
<application path="/">
<virtualDirectory path="/" physicalPath="D:\Test\Test" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:88:" />
</bindings>
<logFile logExtFileFlags="Date, Time, ClientIP, UserName, SiteName, ComputerName, ServerIP, Method, UriStem, UriQuery, HttpStatus, Win32Status, BytesSent, BytesRecv, TimeTaken, ServerPort, UserAgent, Cookie, Referer, ProtocolVersion, Host, HttpSubStatus" logFormat="W3C" logTargetW3C="File, ETW" period="Daily" enabled="true">
<customFields>
<clear />
<add logFieldName="tttt" sourceName="ETag" sourceType="ResponseHeader" />
<add logFieldName="ggg" sourceName="ETag" sourceType="ResponseHeader" />
<add logFieldName="fff" sourceName="HTTP_VERSION" sourceType="ServerVariable" />
<add logFieldName="ffff" sourceName="HTTP_VERSION" sourceType="ServerVariable" />
<add logFieldName="ff" sourceName="Host" sourceType="RequestHeader" />
</customFields>
</logFile>
<traceFailedRequestsLogging enabled="true" directory="C:\inetpub\logs\FailedReqLogFiles" />
</site>
now i want to read the customFields node in above XML and convert its childElement add into Collection.Using below code i can read the customFields node but not able to convert the childElement add inside the customFields into collection .
c#
using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();
ConfigurationSection sitesSection = config.GetSection("system.applicationHost/sites");
ConfigurationElementCollection sitesCollection = sitesSection.GetCollection();
//this will return the node with id=8
ConfigurationElement siteElement = FindElement(sitesCollection, out siteName, "site", "id", @"8");
ConfigurationElementCollection siteCollection = siteElement.GetCollection();
ConfigurationElement logFileElement = siteCollection.GetChildElement("logFile");
var customFields= logFileElement.GetCollection("customFields");
}
how can i convert child node add inside the customFields node into collection in c#?
No comments:
Post a Comment