log4net Tip! Multiple logs with a single OpenSim install

Acres of logs, and they’re all mine!

One of the more advanced ways to run OpenSimulator is to have only one copy of the simulator’s binaries, but run multiple instances on it. It takes a little bit more preparation to set this up, and people like Gwynneth Llewelyn and SignpostMarv have already written good guides on how to do so. Gwynneth’s guide discusses how she deals with logs files, but for some reason the method she uses just doesn’t seem to want to work for me in in either a Windows or Linux environment.

This meant I had to find my own solution, and after a little digging around, I found something that works!

OpenSimulator uses something called log4net to do it’s logging. Some users might not realize that it’s configurable, as it’s not something you can do in the OpenSim.ini configuration file. Instead, its configuration lives in the file OpenSim.exe.config. This is just an XML file that allows one to change various things about an .NET assembly and it’s components. The OpenSimulator Wiki has an article on how to configure log4net in various ways. The part of the OpenSim.exe.config file that we’re most concerned with looks like this:

   <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
     <file value="OpenSim.log" />
     <appendToFile value="true" />
     <layout type="log4net.Layout.PatternLayout">
       <conversionPattern value="%date %-5level - %logger %message%newline" />

We’re only really concerned with just one line of that:

 <file value="OpenSim.log" />

What we need to do here is find a way to change this line so that when we run OpenSim.exe, OpenSim.log gets written to a location of our choosing. And it turns out that we can do this with an environment variable! So, let’s say we create a Windows batch file named “startregion.bat” to start our OpenSim instance that looks like this:

@echo off
set OSIM_LOGPATH="C:\OpenSim\%~1\"
cd C:\OpenSim\bin
OpenSim.exe -inidirectory="C:\OpenSim\%~1\"

The environment variable we’re using here is “OSIM_LOGPATH”, so we’ll need to plug that into our OpenSim.exe.config file.

 <file value="${OSIM_LOGPATH}OpenSim.log" />

Then let’s say we’ve setup an instance that lives in the folder C:\OpenSim\Edumacation\. We could start that instance with the command:

startregion Edumacation

If all goes well, we should wind up with an OpenSim.log file in the directory C:\OpenSim\Edumacation. Huzzah!

I’ve added a short version of this to OpenSimulator’s wiki page on logging, but we know how wikis can be… unless you go looking the for info and know just what it is you’re looking for, you might never run across this. So hopefully this blog post augmenting it will also be helpful. 🙂


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s