Yes, I just spent two hours trying to get some output from Log4Net in Unity3D. The main problem was of course in front of the computer but I also blame the log4net online docs for not having a quick start guide that outputs to a file. I had three problems:

  • I didn’t know what the default working directory of a Unity3D app running in the editor is. (hint: It’s the root of the project folder) So I was looking all over the place for that log file to appear.
  • I copy pasted example configuration snippets from here: log4net Config Examples. I didn’t realize these are not complete config files, but just parts that need to be inserted into a real log4net config.
  • log4net does not report errors regarding to log4net in any way by default. Of course, I didn’t know this either, since who reads the complete documentation to a simple logging API right?
So the result was that log4net was unhappy with my config file but I didn’t notice it since it doesn’t report any errors. Instead, I thought that maybe Unity3D is sandboxing file system access on some level and was chasing around the usual places in the filesystem looking for my newly created log file. Not finding it I tweaked the log4net config file and went looking again. Rinse, repeat. Only after I realized that log4net was not reporting internal errors and then changing this behavior I was notified that my config file was ill formatted. From there getting it to finally work was easy.
I also made some progress with the game design.
 

If you ever need to use the Windows SDK command shell (vcvarsall.bat or setenv.cmd) in an automated fashion, you can use this batch snippet to load it up from a command line. This works for Windows 7 SDK under Windows XP. Other Windows versions might work but are untested.

@ECHO OFF
REM ## This is needed for setenv.cmd later
setlocal EnableDelayedExpansion
REM ## STORE OLD DIR
set olddir=%cd%

REM ## DETERMINE SDK DIR
SET SDKREG=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\Windows\v7.0
SET SDKDIRQUERY=reg query "%SDKREG%" /v InstallationFolder
FOR /F "tokens=2* delims= " %%A IN ('%SDKDIRQUERY%') DO SET SDKDIR=%%B
REM Tab followed by Space ^^^^^^

REM ## STARTUP COMPILE ENVIRONMENT
call "%SDKDIR%\bin\setenv.cmd"

REM ## RESET DIRECTORY
chdir /d %olddir%
REM ## YOUR COMMANDS GO HERE
© 2011 Jörg Rüppel | Impressum Suffusion theme by Sayontan Sinha