Reputation: 1163
I'm using ASP.NET5 / MVC 6. I am trying to use a SQL logger on an app running in Azure Apps. Locally, I can access the directory I want, so I am pretty sure its not a syntax or system agnostic error. This is the part that fails while stepping through on remote debugging. Again, locally it runs and logs normally.
//Local path
private static readonly string _logFilePath = @"C\temp\DatabaseLog.sql";
//Azure App path
private static readonly string _logFilePath = @"\templog\DatabaseLog.sql";
public void Log(LogLevel logLevel, int eventId, object state, Exception exception, Func<object, Exception, string> formatter)
{
var message = string.Format(
"\n\n--{0}\n{1}",
DateTime.Now,
formatter(state, exception));//.Replace(", [", ",\n ["));
File.AppendAllText(_logFilePath, message); // <-- FAILS HERE
}
I have set \templog as a virtual directory in the Azure portal. See image:
I have also created the folder in the project. See image:
Upvotes: 0
Views: 129
Reputation: 615
Wouldn't you still have to map the virtual path to physical?
using either of
private static readonly string _logFilePath = Server.MapPath(@"/templog/DatabaseLog.sql");
or
private static readonly string _logFilePath = HostingEnvironment.MapPath(@"/templog/DatabaseLog.sql");
Have you tried writing to /App_Data?
Does the folder exist on azure?
Maybe there are permissions on the folder that need to be set?
Upvotes: 0
Reputation: 265
The Azure App storage is mapped to d:\home so I would try to change:
//Azure App path
private static readonly string _logFilePath = @"\templog\DatabaseLog.sql";
to
//Azure App path
private static readonly string _logFilePath = @"d:\site\templog\DatabaseLog.sql";
Upvotes: 1