diff --git a/Script/CastorScript.py b/Script/CastorScript.py
index c3962c80acc970449f7a0b8f0284fec6ad164b9c..e347d985fc4ac1040dd8fe21c22911840f5e3850 100755
--- a/Script/CastorScript.py
+++ b/Script/CastorScript.py
@@ -17,6 +17,7 @@ from time import time
 import threading
 import sys
 import os.path
+from os import environ, getenv
 import signal
 import logging, logging.handlers
 from utils import set_log_level
@@ -82,6 +83,38 @@ def main(conf):
     set_log_level(LogLevel, mainLog)
     logger.addHandler(mainLog)
 
+    ##### Setup Environment for ERS #####
+    os.environ["TDAQ_PARTITION"]=conf.partition
+    os.environ["TDAQ_APPLICATION_NAME"]="CastorScript.py"
+    os.environ["TDAQ_ERS_ERROR"]=conf.ers_error
+    os.environ["TDAQ_ERS_INFO"]=conf.ers_info
+    os.environ["TDAQ_ERS_WARNING"]=conf.ers_warning
+
+
+    # check if there is a partition to log to
+    from ispy import IPCPartition
+    if IPCPartition(conf.partition).isValid():
+        logInfo = {'file':logger.findCaller()[0],'line':logger.findCaller()[1]}
+        logger.info("CastorScript found partition '%s'" % conf.partition,extra=logInfo)
+    else:
+        logInfo = {'file':logger.findCaller()[0],'line':logger.findCaller()[1]}
+        logger.error("CastorScript could not find partition '%s', not logging to mrs" 
+                     % conf.partition, extra=logInfo)
+
+    ##### Setup ERS #####
+    #only if there is a partition, try to add ers backend
+    if IPCPartition(conf.partition).isValid():
+        try:
+            import ers
+            ers.addLoggingHandler("main")
+            logInfo = {'file':logger.findCaller()[0],'line':logger.findCaller()[1]}
+            logger.info("CastorScript is now logging to partition '%s'" 
+                        % conf.partition,extra=logInfo)
+        except Exception,ex:
+            logInfo = {'file':logger.findCaller()[0],'line':logger.findCaller()[1]}
+            logger.error("CastorScript could not create ERS, reason is '%s'" 
+                         % str(ex),extra=logInfo)
+
     ##### Create db logger #####
     dbLog = logging.FileHandler(os.path.join(conf.LogDir,'DatabaseLog.out'),
                                 'w')
diff --git a/Script/Conf.cfg b/Script/Conf.cfg
index 72d9673731ce4acd326be51f1ab32c2932e5f224..2ab38e1fce4337f84aaa3eba03f582b7cafd19ca 100755
--- a/Script/Conf.cfg
+++ b/Script/Conf.cfg
@@ -22,6 +22,17 @@ mailSender: 'someone@cern.ch'
 # e.g. ['/path/to/your/modules','/another/path']
 pythonPathPrepend: []
 
+
+########## VARIABLES FOR ERS ##############
+
+# Partition to log to
+partition: "part_l2ef_lmtest"
+
+# Stream ERS messages to
+ers_info: "mrs"
+ers_warning: "mrs"
+ers_error: "mrs"
+
 ########## METADATA DATABASE ##########
 
 # Oracle connection string
diff --git a/Script/Conf.py b/Script/Conf.py
index 8f4b337a431146f6c82d10e5e435d0ae97605b55..9a4100e7cceb9ddbdfefe816aaca1abcca2a5d23 100755
--- a/Script/Conf.py
+++ b/Script/Conf.py
@@ -48,6 +48,18 @@ class Conf:
             self.pythonPathPrepend = cfg.pythonPathPrepend
         except AttributeError:
             pass
+
+
+        ########## Variables for ERS ##########
+
+        # Partition to log to
+        self.partition = cfg.partition
+
+        # Stream ers to
+        self.ers_error = cfg.ers_error
+        self.ers_info = cfg.ers_info
+        self.ers_warning = cfg.ers_warning
+
             
         ########## METADATA DATABASE ##########