Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set linux nlog folder in asp.net core

I use NLog in my asp.net core 2.0 applications, and I want to deploy it to Ubuntu. I can find lots of threads and articles, but all of them are deploy in Windows.

My nlog.config snippet looks as below,

<target xsi:type="File" name="ownlog" fileName="${var:configDir}\nlog-own.log"
             layout="${longdate}|${event-properties:item=EventId.Id}|${logger}|${uppercase:${level}}|  ${message} ${exception}" />

and in my Startup.cs file, I set the configDir as below,

LogManager.Configuration.Variables["configDir"] = "\\var\\log";

It doesn't work. Anyone can help? How can I store the log file in \var\log folder?

Thanks

like image 489
Allen4Tech Avatar asked Oct 22 '25 00:10

Allen4Tech


1 Answers

You'll have to change your path from double backslash to a single slash. If you want to keep both environments, you can do something like this:

if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
// use windows path
else
// use linux path
like image 128
jom Avatar answered Oct 23 '25 12:10

jom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!