asp.net 在C盘创建 log.txt出错

简介:   在服务器上,C盘一般是不允许通过WEB创建文档的,除非你在权限设置中打开,改为其他盘即可。      public static void LOG(string msg = "")        {            try            {                string path = "c:\\log.
  
在服务器上,C盘一般是不允许通过WEB创建文档的,除非你在权限设置中打开,改为其他盘即可。

      public static void LOG(string msg = "")
        {
            try
            {
                string path = "c:\\log.txt";

//                string path = @"c:\log.txt";
                if (System.IO.File.Exists(path) == false)
                    using (System.IO.FileStream writer = System.IO.File.Create(path))
                    {
                        writer.Close();
                    }
                using (System.IO.StreamWriter writer = System.IO.File.AppendText(path))
                {
                    writer.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff") + "->" + string.Concat(msg, Environment.NewLine));
                    writer.Close();
                }
               string path = @"d:\log.txt";
                System.IO.StreamWriter writer;
                if (System.IO.File.Exists(path) == false)
                    writer = System.IO.File.CreateText(path);
                else
                    writer = System.IO.File.AppendText(path);
               writer.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff") + "->" + string.Concat(msg, Environment.NewLine));
                writer.Close();

            }
            catch (System.Exception ex)
            {
                int i = 00;
            }
        }
相关实践学习
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
【涂鸦即艺术】基于云应用开发平台CAP部署AI实时生图绘板
目录
相关文章
|
开发框架 .NET Docker
【Azure 应用服务】App Service .NET Core项目在Program.cs中自定义添加的logger.LogInformation,部署到App Service上后日志不显示Log Stream中的问题
【Azure 应用服务】App Service .NET Core项目在Program.cs中自定义添加的logger.LogInformation,部署到App Service上后日志不显示Log Stream中的问题
278 1
|
C++
VS-2019-.NET-C#使用log4net打日志,程序日志记录
VS-2019-.NET-C#使用log4net打日志,程序日志记录
394 0
.Net Core使用 Log4Net
.Net Core使用 Log4Net
200 0
|
XML 数据采集 开发框架
asp.net core添加全局异常处理及log4net、Nlog应用
文章来源于阿里云 MVP郭联钰。
750 0
|
.NET 开发框架 数据格式