You are viewing a plain text version of this content. The canonical link for it is here.
Posted to log4net-user@logging.apache.org by Martin Fetzel <ma...@gmx.net> on 2010/12/09 18:16:13 UTC
log4net serializable?
Hello,
we rewrote our pluginmanager and now the plugins have to be
serializable.
The plugins should also be able to log. So the interface of the plugins
looks something like that. Public void run(args[], log4net plogger).
But now (with the new pluginmanager) this isn’t working because log4net
isn’t serializable.
How can i make log4net serializable? Have any one a good solution for my
problem?
Greetings
martin
AW: log4net serializable?
Posted by Martin Fetzel <ma...@gmx.net>.
I tried to replace the ILOG object with the string as you have suggested.
The next step is to tell the plugin to use the same config file as the host, because I want that the plugin is writing the logs into the same source as the host. Getting the logger and using the same config works. But when im logging something in the plugin, the plugin logger says that an other process is using the log file (cause of the different appdomains).
At the moment the config file of the logger is using the fileappender.
So how i'm getting the host and the plugin writing in the same file / database / eventlogger? How is this possible?
If it would possible to hand through the Ilog object from the host to the plugin this would be no problem.
Greetings
martin
-----Ursprüngliche Nachricht-----
Von: Martin Fetzel [mailto:martin.fetzel@gmx.net]
Gesendet: Freitag, 10. Dezember 2010 13:21
An: Log4NET User
Betreff: Re: log4net serializable?
thanks for the suggested solution. I'ill check this out.
On Thu, 2010-12-09 at 23:10 -0600, Curt Arnold wrote:
> On Dec 9, 2010, at 1:39 PM, Martin Fetzel wrote:
>
> > Yes it seems that i have to serialize the logger itself. The problem
> > is that the new pluginmanager is using appdomains and the Ilog
> > object should be serializeable. When in the Appdomain an instance of
> > the plugin will be created an exception will be thrown.
>
>
> LoggingEvent's are serializable, but serializing loggers isn't either practical or desirable. If it were so, you'd be in essence storing the state of the entire hierarchy of loggers, appenders and such since only if you had the entire graph of objects would you really capture the state of a logger and then you'd need to be able to reestablish any open files, sockets, etc to get everything to an functionally equivalent state.
>
> So, it appears that you have a serializable class that has a ILog instance member. Your solution is to replace the ILog member with a static member or with something serializable (string for example) that can be used to reacquire the logger after deserialization. If static isn't appropriate, the next simplest approach would be replace the ILog with a string containing the logger name and to call GetLogger() on demand to get a logger.
Re: log4net serializable?
Posted by Martin Fetzel <ma...@gmx.net>.
thanks for the suggested solution. I'ill check this out.
On Thu, 2010-12-09 at 23:10 -0600, Curt Arnold wrote:
> On Dec 9, 2010, at 1:39 PM, Martin Fetzel wrote:
>
> > Yes it seems that i have to serialize the logger itself. The problem is
> > that the new pluginmanager is using appdomains and the Ilog object
> > should be serializeable. When in the Appdomain an instance of the plugin
> > will be created an exception will be thrown.
>
>
> LoggingEvent's are serializable, but serializing loggers isn't either practical or desirable. If it were so, you'd be in essence storing the state of the entire hierarchy of loggers, appenders and such since only if you had the entire graph of objects would you really capture the state of a logger and then you'd need to be able to reestablish any open files, sockets, etc to get everything to an functionally equivalent state.
>
> So, it appears that you have a serializable class that has a ILog instance member. Your solution is to replace the ILog member with a static member or with something serializable (string for example) that can be used to reacquire the logger after deserialization. If static isn't appropriate, the next simplest approach would be replace the ILog with a string containing the logger name and to call GetLogger() on demand to get a logger.
Re: log4net serializable?
Posted by Curt Arnold <ca...@apache.org>.
On Dec 9, 2010, at 1:39 PM, Martin Fetzel wrote:
> Yes it seems that i have to serialize the logger itself. The problem is
> that the new pluginmanager is using appdomains and the Ilog object
> should be serializeable. When in the Appdomain an instance of the plugin
> will be created an exception will be thrown.
LoggingEvent's are serializable, but serializing loggers isn't either practical or desirable. If it were so, you'd be in essence storing the state of the entire hierarchy of loggers, appenders and such since only if you had the entire graph of objects would you really capture the state of a logger and then you'd need to be able to reestablish any open files, sockets, etc to get everything to an functionally equivalent state.
So, it appears that you have a serializable class that has a ILog instance member. Your solution is to replace the ILog member with a static member or with something serializable (string for example) that can be used to reacquire the logger after deserialization. If static isn't appropriate, the next simplest approach would be replace the ILog with a string containing the logger name and to call GetLogger() on demand to get a logger.
Re: log4net serializable?
Posted by Ross Hinkley <ro...@gmail.com>.
Could you pass the name of the configuration file or logger and configure
the logger when that instantiate method is called (or something similar)?
-Ross
On Thu, Dec 9, 2010 at 1:39 PM, Martin Fetzel <ma...@gmx.net> wrote:
> Yes it seems that i have to serialize the logger itself. The problem is
> that the new pluginmanager is using appdomains and the Ilog object
> should be serializeable. When in the Appdomain an instance of the plugin
> will be created an exception will be thrown.
>
>
> protected virtual IPLUGIN InstantiatePlugin(String pPluginType, ILog
> pLog)
> {
>
> //created _appDom for plugin
>
> _Instance =
> this._appDom.CreateInstanceFromAndUnwrap(_AssemblyPath, pPluginType) as
> IPLUGIN;
>
>
> //set logger
> _Instance.Logger = pLog; <- this will throw the following
> exception:
>
>
>
> 'log4net.Core.LogImpl' in Assembly 'log4net,
> Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' is
> not marked as serializable.
>
>
> This is why im searching for an serializeable ILog object.
>
>
> greetings
>
>
>
>
> On Thu, 2010-12-09 at 11:59 -0600, Ross Hinkley wrote:
> > Do you have to serialize the logger itself? Why not ignore it with
> > the XmlIgnore attribute?
> >
> > -Ross
> >
> > On Thu, Dec 9, 2010 at 11:31 AM, Martin Fetzel <ma...@gmx.net>
> > wrote:
> > Hello,
> >
> > im sry, that im reposting this, but i forgot to post the
> > correct
> > typ /code which im using.
> >
> > ILog _log = LogManager.GetLogger(typeof(FileSyncService));
> >
> > Interface of Plugin: void SyncDir(ILog pLog, string[] args);
> >
> > So the Object which returns LogManager.GetLogger should be
> > serializable.
> > Any one got an idea how i can fix this?
> >
> > greetings
> >
> >
> >
> > On Thu, 2010-12-09 at 18:16 +0100, Martin Fetzel wrote:
> > > Hello,
> > >
> > > we rewrote our pluginmanager and now the plugins have to be
> > > serializable.
> > >
> > > The plugins should also be able to log. So the interface of
> > the plugins
> > > looks something like that. Public void run(args[], log4net
> > plogger).
> > >
> > > But now (with the new pluginmanager) this isn’t working
> > because log4net
> > > isn’t serializable.
> > >
> > > How can i make log4net serializable? Have any one a good
> > solution for my
> > > problem?
> > >
> > > Greetings
> > >
> > >
> > >
> > > martin
> > >
> >
> >
> >
> >
>
>
>
Re: log4net serializable?
Posted by Martin Fetzel <ma...@gmx.net>.
Yes it seems that i have to serialize the logger itself. The problem is
that the new pluginmanager is using appdomains and the Ilog object
should be serializeable. When in the Appdomain an instance of the plugin
will be created an exception will be thrown.
protected virtual IPLUGIN InstantiatePlugin(String pPluginType, ILog
pLog)
{
//created _appDom for plugin
_Instance =
this._appDom.CreateInstanceFromAndUnwrap(_AssemblyPath, pPluginType) as
IPLUGIN;
//set logger
_Instance.Logger = pLog; <- this will throw the following
exception:
'log4net.Core.LogImpl' in Assembly 'log4net,
Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' is
not marked as serializable.
This is why im searching for an serializeable ILog object.
greetings
On Thu, 2010-12-09 at 11:59 -0600, Ross Hinkley wrote:
> Do you have to serialize the logger itself? Why not ignore it with
> the XmlIgnore attribute?
>
> -Ross
>
> On Thu, Dec 9, 2010 at 11:31 AM, Martin Fetzel <ma...@gmx.net>
> wrote:
> Hello,
>
> im sry, that im reposting this, but i forgot to post the
> correct
> typ /code which im using.
>
> ILog _log = LogManager.GetLogger(typeof(FileSyncService));
>
> Interface of Plugin: void SyncDir(ILog pLog, string[] args);
>
> So the Object which returns LogManager.GetLogger should be
> serializable.
> Any one got an idea how i can fix this?
>
> greetings
>
>
>
> On Thu, 2010-12-09 at 18:16 +0100, Martin Fetzel wrote:
> > Hello,
> >
> > we rewrote our pluginmanager and now the plugins have to be
> > serializable.
> >
> > The plugins should also be able to log. So the interface of
> the plugins
> > looks something like that. Public void run(args[], log4net
> plogger).
> >
> > But now (with the new pluginmanager) this isn’t working
> because log4net
> > isn’t serializable.
> >
> > How can i make log4net serializable? Have any one a good
> solution for my
> > problem?
> >
> > Greetings
> >
> >
> >
> > martin
> >
>
>
>
>
Re: log4net serializable?
Posted by Ross Hinkley <ro...@gmail.com>.
Do you have to serialize the logger itself? Why not ignore it with the
XmlIgnore attribute?
-Ross
On Thu, Dec 9, 2010 at 11:31 AM, Martin Fetzel <ma...@gmx.net>wrote:
> Hello,
>
> im sry, that im reposting this, but i forgot to post the correct
> typ /code which im using.
>
> ILog _log = LogManager.GetLogger(typeof(FileSyncService));
>
> Interface of Plugin: void SyncDir(ILog pLog, string[] args);
>
> So the Object which returns LogManager.GetLogger should be serializable.
> Any one got an idea how i can fix this?
>
> greetings
>
>
> On Thu, 2010-12-09 at 18:16 +0100, Martin Fetzel wrote:
> > Hello,
> >
> > we rewrote our pluginmanager and now the plugins have to be
> > serializable.
> >
> > The plugins should also be able to log. So the interface of the plugins
> > looks something like that. Public void run(args[], log4net plogger).
> >
> > But now (with the new pluginmanager) this isn’t working because log4net
> > isn’t serializable.
> >
> > How can i make log4net serializable? Have any one a good solution for my
> > problem?
> >
> > Greetings
> >
> >
> >
> > martin
> >
>
>
>
Re: log4net serializable?
Posted by Martin Fetzel <ma...@gmx.net>.
Hello,
im sry, that im reposting this, but i forgot to post the correct
typ /code which im using.
ILog _log = LogManager.GetLogger(typeof(FileSyncService));
Interface of Plugin: void SyncDir(ILog pLog, string[] args);
So the Object which returns LogManager.GetLogger should be serializable.
Any one got an idea how i can fix this?
greetings
On Thu, 2010-12-09 at 18:16 +0100, Martin Fetzel wrote:
> Hello,
>
> we rewrote our pluginmanager and now the plugins have to be
> serializable.
>
> The plugins should also be able to log. So the interface of the plugins
> looks something like that. Public void run(args[], log4net plogger).
>
> But now (with the new pluginmanager) this isn’t working because log4net
> isn’t serializable.
>
> How can i make log4net serializable? Have any one a good solution for my
> problem?
>
> Greetings
>
>
>
> martin
>