serilog: Rollingfile relative path not working in ASP.NET MVC + IIS Express
I’m using the serilog on first application, it’s ASP.NET MVC app + IIS Express using serilog, configured with following AppSetting configs,
<add key="serilog:minimum-level" value="Verbose" />
<add key="serilog:write-to:RollingFile.pathFormat" value="logs\log-{Date}.txt" />
<add key="serilog:write-to:RollingFile.retainedFileCountLimit" value="3" />
the application creates log file at C:\Program Files (x86)\IIS Express\logs\
Is there a way to to use the relative path. It works if i use a full path!
I’m using log4net in other MVC apps, it resolves to relative path, though!
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Comments: 21 (4 by maintainers)
Folks, if anyone has ideas for baking this in more elegantly I’d be interested; for now I think the following in
Global.asax.csbefore configuring the logger:and the following config:
is a pretty good option. @SathishN thanks again for the input on this!
Here is how I did it with an ASP.NET MVC 4/5 application.
Add the following to the web.config file:
Then add the following to the
Application_Startin Global.asax:@SathishN thanks for the follow-up!
I wonder - would setting:
cover it? It’d be interesting to hear if this fixes the issue.
We can’t make this change globally because it would break those already depending on the use of log paths relative to the current directory. If
cding works, we might be able to do something in https://github.com/serilogweb/classic.Cheers!
@navnit-kumar, thanks for your help.
I managed to get it working. My problem for two things:
<add key="serilog:using:RollingFile" value="Serilog.Sinks.RollingFile" />in the config fileC:\Program Files\IIS Express… because I was hosting in NancyFx. I tried to override the NancyFxIRootPathProvideras in the following solution but it did not work for the logger…Look like I’m the only person having this issue,
I looked into the code https://github.com/serilog/serilog/blob/dev/src/Serilog.FullNetFx/Sinks/RollingFile/TemplatedPathRoller.cs#L47
Following code used to resolving the path,
Instead of Environment.CurrentDirectory, using AppDomain.CurrentDomain.BaseDirectory, should fix this problem.
I’m running the web app on _IIS Express, so the current directory is _C:\Program Files (x86)\IIS Express, not my work project working directory!!
any thoughts? If your are good, I could submit a pull request with my fix!