【问题标题】:Could not find a part of the path 'D:\Users\*\app\PublishedWebsites\WebMatrixWebsite\Logs'找不到路径“D:\Users\*\app\PublishedWebsites\WebMatrixWebsite\Logs”的一部分
【发布时间】:2017-02-06 13:29:59
【问题描述】:

我正在使用某种方法在 txt 中写入日志文件,并且在 Visual Studio 代码的本地运行期间有效地写入日志。

C:\Users\ARSLAN\Documents\Visual Studio 2015\Projects\ApplicationCheckCrone\ApplicationCheckCrone\Logs

string logFilePath = "Log-" + System.DateTime.Today.ToString("MM-dd-yyyy") + "." + "txt";

            logFileInfo = new FileInfo(logFilePath);
            File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "bin" + logFilePath, strLog);

这里是日志的位置。但是当我在 appharbor 的服务器上发布我的网站时出现错误。单击按钮后,我收到此错误。

Could not find a part of the path 'D:\Users\apphb113ae29dc16698\app\_PublishedWebsites\WebMatrixWebsite\Logs'.

下面是堆栈跟踪:

堆栈跟踪:

[DirectoryNotFoundException: Could not find a part of the path 'D:\Users\apphb113ae29dc16698\app\_PublishedWebsites\WebMatrixWebsite\Logs'.]
   System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +366
   System.IO.FileSystemEnumerableIterator`1.CommonInit() +268
   System.IO.FileSystemEnumerableIterator`1..ctor(String path, String originalUserPath, String searchPattern, SearchOption searchOption, SearchResultHandler`1 resultHandler, Boolean checkHost) +434
   System.IO.Directory.GetFiles(String path) +70
   ApplicationCheckCrone.LogsData.BindData() +91
   ApplicationCheckCrone.LogsData.Page_Load(Object sender, EventArgs e) +24
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +95
   System.Web.UI.Control.LoadRecursive() +59
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678

如何解决这个问题,以便在服务器上也显示我的日志文件。感谢任何帮助将不胜感激。谢谢

【问题讨论】:

    标签: c# path relative-path server.mappath


    【解决方案1】:
    File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + "\bin" + logFilePath, strLog);
    

    注意额外的“\”。

    AppDomain.BaseDirectory 的值不以反斜杠结尾。

    【讨论】:

      猜你喜欢
      • 2011-09-09
      • 1970-01-01
      • 2021-12-22
      • 2013-01-13
      • 1970-01-01
      • 2017-05-03
      • 1970-01-01
      • 2021-04-20
      • 1970-01-01
      相关资源
      最近更新 更多