English 中文(简体)
目录已创建目录, 但文件没有在服务器上创建, 本地运行罚款
原标题:Directory is created but File is not getting created on server, local runs fine

下面的代码问题在于目录正在服务器上创建, 但是文件没有被创建, 当我在系统上本地运行时, 它运行正常, 请建议可以做什么, 这是我的优先级 1. Thnx 。

public static void CreateLog(string strToLog)
    {
        try
        {
            string excepfile = "CacheServerLogs_" + DateTime.Now.ToShortDateString().Replace("-", "_") + ".txt";
            FileStream fs = null;
            StreamWriter sw = null;
            string mydocpath = "C:\CacheServerLogs";
            if (!Directory.Exists(mydocpath))
                Directory.CreateDirectory(mydocpath);
            string exceptionfile = Path.Combine(mydocpath, excepfile);
            //string exceptionfile = mydocpath + "\" + excepfile;
            if (!File.Exists(exceptionfile))
                fs = File.Create(exceptionfile);
            else
                sw = File.AppendText(exceptionfile);
            sw = sw == null ? new StreamWriter(fs) : sw;
            sw.WriteLine(DateTime.Now.ToString() + " - " + strToLog);
            sw.Close();
            if (fs != null)
                fs.Close();
        }
        catch (Exception ex)
        {
            HandleException(ex);
        }
    }

可能存在用户权限问题, 但我尝试这样做... 给文件夹所有可能的许可...

最佳回答

实际上错误是用

string excepfile = "CacheServerLogs_" + DateTime.Now.ToShortDateString().Replace("-", "_") + ".txt";

在我的系统中,格式是22-05-2012,但在服务器上是2252012,所以这在路径上造成了错误,但找不到...

问题回答

Try using File.CreateText or File.Write

您显然正在试图写入日志文件, 我通常建议您使用一个“ 标准” 图书馆来这样做, 比如 http:// logbook.apache.org/log4net/" rel=“ nofollow” >log4net 或< a href="http://nlog- project.org/" rel=“ nofollow” >NLog 。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签