using nlog - asp.net on shared hosting

3 messages Options
Embed this post
Permalink
tomo

using nlog - asp.net on shared hosting

Reply Threaded More More options
Print post
Permalink
Hello there,
I tried to use nlog on shared hosting but unfortunatelly it seems not to be possible.
It works perfect in full trust, but I bet this piece of code is not allowed on medium trust:

BaseFileAppender - WindowsCreateFile calls Win32FileHelper and p/invoke DllImport kernel32.dll CreateFile

Is there any solution for that?
Jaroslaw Kowalski

Re: using nlog - asp.net on shared hosting

Reply Threaded More More options
Print post
Permalink
Unfortunately NLog was not designed or tested to run in partial trust so default logging options require P/Invoke which causes issues.

If you can re-compile NLog for your installation, you should be able to work-around this particular issue by opening src\NLog\Internal\FileAppenders\BaseFileAppender.cs file and commenting out or removing the lines in #if/#endif region.

#if !NETCF
            if (PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.WindowsNT) ||
                    PlatformDetector.IsCurrentOSCompatibleWith(RuntimeOS.Windows))
            {
                return WindowsCreateFile(FileName, allowConcurrentWrite);
            }
#endif

            return new FileStream(FileName,
                FileMode.Append,
                FileAccess.Write,
                fileShare,
                _createParameters.BufferSize);

I don't have a way of verifying this fix, so please let me know if it works for you.
tomo

Re: using nlog - asp.net on shared hosting

Reply Threaded More More options
Print post
Permalink
Thanks for the idea. I'll try it in a few days.
Do I need to configure something extra for ASP.NET multithreaded environment - any filelocks, mutexes, queues? Is that safe for use it on IIS7 platform?