Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 以特定格式生成文本文件_C#_Visual Studio 2012 - Fatal编程技术网

C# 以特定格式生成文本文件

C# 以特定格式生成文本文件,c#,visual-studio-2012,C#,Visual Studio 2012,我有这个方法,我想生成日志文本(txt)文件,文件结构将遵循传递给这个方法的查询字符串数据,如culturename,langid,themeid,salescannel。如果有四个参数,我希望文件以culturename\u sales channel\u themeid\u langid.txt的形式生成,如果有两个参数,则以sales channel\u themeid\u langid.txt的形式生成。请帮助我创建此格式的日志文本文件,或者如何单独创建 private void Lo

我有这个方法,我想生成日志文本(txt)文件,文件结构将遵循传递给这个方法的查询字符串数据,如
culturename
langid
themeid
salescannel
。如果有四个参数,我希望文件以
culturename\u sales channel\u themeid\u langid.txt
的形式生成,如果有两个参数,则以
sales channel\u themeid\u langid.txt
的形式生成。请帮助我创建此格式的日志文本文件,或者如何单独创建

 private void Log(string message, bool debugOnly, bool waitOnThis, LogType logType, string culturename, int langid, int themeid, int saleschannel)

        {
            string logFormat = Environment.NewLine + "{0}\t  {1}\t{2}" + Environment.NewLine;
            //message = message + " - " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fffffff");
            message = string.Format(logFormat, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"),logType.ToString().Substring(0,3).ToUpper(), message);
            _logFileName = string.Format(_logFileNamePattren, _jobConfigurationData.Name, LogFileId, _logFileDate);
            string filePath = _jobConfigurationData.LogFolderPath;
            if (!string.IsNullOrEmpty(filePath))
                filePath += "\\" + _logFileName;
            if (debugOnly == false || (debugOnly && _jobConfigurationData.BuildMode == BuildMode.Debug))
            {
                if (!string.IsNullOrEmpty(filePath))
                {
                    if(!Directory.Exists(Path.GetDirectoryName(filePath)))
                        Directory.CreateDirectory(Path.GetDirectoryName(filePath));
                    File.AppendAllText(filePath, message, System.Text.Encoding.UTF8);
                }
                Console.Write(message);
            }
像这样的

_logFileName = (string.IsNullOrEmpty(culturename)? string.Empty : (culturename + "_")) +
(saleschannel == 0 ? string.Empty : (saleschannel+"_")) +
themeid+ "_" + langid +".txt";

或者您正在谈论函数重载?

如果有N个参数出现,您是什么意思?是否可以使用可为null的int作为参数类型?我希望根据参数值重命名文件,并且每次调用该方法时日志文本文件都依赖于它。我正在制作一个基于国家,地区和城市产品的网站,并生成日志文件,我需要根据其价值结构。是的,我理解,但它仍然不清楚你所说的“如果有N个参数来了”是什么意思。显示一些输入和输出示例。无论如何,这个方法做的太多了,创建一个基于输入参数生成文件名的方法。