src/LogsearchShipper.Core/LogsearchShipperProcessManager.cs
/// <summary>
/// We're expecting a config that looks like this:
///    
///   {
///   "network": {
///   "servers": [ "endpoint.example.com:5034" ],
///   "ssl ca": "C:\\Logs\\mycert.crt",
///   "timeout": 23
///   }
///   ,"files": [
///   {
///       "paths": [ "myfile.log" ],
///       "fields": {
///       "@type": "myfile_type",
///       "field1": "field1 value"
///       "field2": "field2 value"
///       }
///   },
///   {
///       "paths": [ "C:\\Logs\\myfile.log" ],
///       "fields": {
///       "@type": "type\/subtype",
///       "key\/subkey": "value\/subvalue"
///       }
///   }
///   ]
///}
/// </summary>
We're expecting a config that looks like this.


We ' re expecting a config that looks like this .
internal void SetupConfigFile()
	    {
            var LogsearchShipperConfig = ConfigurationManager.GetSection("LogsearchShipperGroup/LogsearchShipper") as LogsearchShipperSection;
            Debug.Assert(LogsearchShipperConfig != null, "LogsearchShipperConfig != null");
	        ConfigFile = Path.GetTempFileName();
	        var networkSection =
	            @"""network"": {
    ""servers"": [ ""{0}"" ],
    ""ssl ca"": ""{1}"",
    ""timeout"": {2}
  },"
	            .Replace("{0}", HttpUtility.JavaScriptStringEncode(LogsearchShipperConfig.Servers))
	            .Replace("{1}", HttpUtility.JavaScriptStringEncode(LogsearchShipperConfig.SSL_CA))
	            .Replace("{2}", HttpUtility.JavaScriptStringEncode(LogsearchShipperConfig.Timeout.ToString(CultureInfo.InvariantCulture)));
            var filesSection = " \"files\": [\n";
            for (int i = 0; i < LogsearchShipperConfig.Watchs.Count; i++)
            {
                WatchElement watch = LogsearchShipperConfig.Watchs[i];
                filesSection += "  {\n";
                filesSection += "    \"paths\": [ \""+HttpUtility.JavaScriptStringEncode(watch.Files)+"\" ],\n";
                filesSection += "    \"fields\": {\n";
                filesSection += "      \"@type\": \""+HttpUtility.JavaScriptStringEncode(watch.Type)+"\"\n";
                foreach (FieldElement field in watch.Fields)
                {
                    filesSection += "      ,\"" + HttpUtility.JavaScriptStringEncode(field.Key) + "\": \"" + HttpUtility.JavaScriptStringEncode(field.Value) + "\"\n";
                }
                filesSection += "    }\n";
                filesSection += "  }";
                if (i < LogsearchShipperConfig.Watchs.Count - 1) { filesSection += ","; }
                filesSection += "\n";
            }
            filesSection += "]\n";
            var config = "{\n" + networkSection + "\n" + filesSection + "}";
            File.WriteAllText(ConfigFile, config);
	    }
internal void SetupConfigFile ( ) { var LogsearchShipperConfig = ConfigurationManager . GetSection ( " " ) as LogsearchShipperSection ; Debug . Assert ( LogsearchShipperConfig != null , " " ) ; ConfigFile = Path . GetTempFileName ( ) ; var networkSection = @"""network"": {
    ""servers"": [ ""{0}"" ],
    ""ssl ca"": ""{1}"",
    ""timeout"": {2}
  }," . Replace ( " " , HttpUtility . JavaScriptStringEncode ( LogsearchShipperConfig . Servers ) ) . Replace ( " " , HttpUtility . JavaScriptStringEncode ( LogsearchShipperConfig . SSL_CA ) ) . Replace ( " " , HttpUtility . JavaScriptStringEncode ( LogsearchShipperConfig . Timeout . ToString ( CultureInfo . InvariantCulture ) ) ) ; var filesSection = " \" \" \n " ; for ( int i = 0 ; i < LogsearchShipperConfig . Watchs . Count ; i ++ ) { WatchElement watch = LogsearchShipperConfig . Watchs [ i ] ; filesSection += " \n " ; filesSection += " \" \" \" " + HttpUtility . JavaScriptStringEncode ( watch . Files ) + " \" \n " ; filesSection += " \" \" \n " ; filesSection += " \" \" \" " + HttpUtility . JavaScriptStringEncode ( watch . Type ) + " \" \n " ; foreach ( FieldElement field in watch . Fields ) { filesSection += " \" " + HttpUtility . JavaScriptStringEncode ( field . Key ) + " \" \" " + HttpUtility . JavaScriptStringEncode ( field . Value ) + " \" \n " ; } filesSection += " \n " ; filesSection += " " ; if ( i < LogsearchShipperConfig . Watchs . Count - 1 ) { filesSection += " " ; } filesSection += " \n " ; } filesSection += " \n " ; var config = " \n " + networkSection + " \n " + filesSection + " " ; File . WriteAllText ( ConfigFile , config ) ; }
We're expecting a config that looks like this:
We ' re expecting a config that looks like this :