c# - Allotted timeout while logging System.Net on Trace level -
i'm having issue program. i've created service logging actions nlog. next service i've created tool catch logging , show user. connection based on wsdualhttpbinding.
besides actions of service, i'm logging [system.net], [system.servicemodel] , [system.windows] complete log report.
now i'm getting timeoutexception: message not transferred within allotted timeout of 00:01:00. there nog space available in reliable channel's transfer window. etc...
i've found out exception thrown when loglevel system.net.* set trace. otherwise exception won't thrown.
i've tried multiple solutions increasing timeout; setting defaultconnectionlimit; setting servicebehaviorattribute , many more. none of them worked me...
could me this?
consoleapplication service:
class program { static void main(string[] args) { ioc.kernel.bind<ilogging>().toconstant(new logging()); try { //normal binding var binding = new basichttpbinding(); binding.security.mode = basichttpsecuritymode.transportcredentialonly; binding.security.transport.clientcredentialtype = httpclientcredentialtype.windows; var host = new servicehost(typeof(contract)); host.description.behaviors.find<servicedebugbehavior>().includeexceptiondetailinfaults = true; var path = "http://address:port/icontract"; host.addserviceendpoint(typeof(icontract), binding, path); host.open(); //duplex binding var duplexbinding = new wsdualhttpbinding(); duplexbinding.security.mode = wsdualhttpsecuritymode.message; duplexbinding.security.message.clientcredentialtype = messagecredentialtype.windows; var duplexhost = new servicehost(typeof(duplexcontract)); duplexhost.description.behaviors.find<servicedebugbehavior>().includeexceptiondetailinfaults = true; var duplexpath = "http://address:port/iduplexcontract"; duplexhost.addserviceendpoint(typeof(iduplexcontract), duplexbinding, duplexpath); duplexhost.open(); ioc.kernel.get<ilogging>().log("listening......."); } catch (exception ex) { ioc.kernel.get<ilogging>().log(ex.tostring()); } console.readline(); } }
interfaces service:
[servicecontract] public interface icontract { [operationcontract] void update(string i); } [servicecontract(callbackcontract = typeof(iduplexcontractcallback), sessionmode = sessionmode.required)] public interface iduplexcontract { [operationcontract(isoneway = true)] void addlistener(); } public interface iduplexcontractcallback { [operationcontract(isoneway = true)] void logger(string obj); [operationcontract(isoneway = true)] void receivedcalculate(int i); } public interface ilogging { void log(string message); void addobserver(action<string> addeventlog); }
implementations service:
[servicebehavior(instancecontextmode = instancecontextmode.single)] public class duplexcontract : iduplexcontract { public void addlistener() { ioc.kernel.get<ilogging>().addobserver(operationcontext.current.getcallbackchannel<iduplexcontractcallback>().logger); ioc.kernel.get<ilogging>().log("added listener"); } } [servicebehavior(instancecontextmode = instancecontextmode.single)] public class contract : icontract { public void update(string i) { ioc.kernel.get<ilogging>().log(string.format("received: {0}", i)); } } public class logging : ilogging { public logging() { if (logmanager.configuration == null) { logmanager.configuration = new loggingconfiguration(); } target consoletarget; consoletarget = logmanager.configuration.findtargetbyname(nameof(consoletarget)); if (consoletarget == null) { consoletarget = new coloredconsoletarget() { layout = "${longdate} [${logger}] [${level:uppercase=true}]: ${message} ${onexception:inner=${newline} ${exception:format=tostring:maxinnerexceptionlevel=4:innerformat=tostring:seperator=\r\n}}", name = nameof(consoletarget), usedefaultrowhighlightingrules = false, }; (consoletarget coloredconsoletarget).rowhighlightingrules.add(new consolerowhighlightingrule(conditionparser.parseexpression("level == loglevel.fatal"), consoleoutputcolor.magenta, consoleoutputcolor.nochange)); (consoletarget coloredconsoletarget).rowhighlightingrules.add(new consolerowhighlightingrule(conditionparser.parseexpression("level == loglevel.error"), consoleoutputcolor.red, consoleoutputcolor.nochange)); (consoletarget coloredconsoletarget).rowhighlightingrules.add(new consolerowhighlightingrule(conditionparser.parseexpression("level == loglevel.warn"), consoleoutputcolor.yellow, consoleoutputcolor.nochange)); (consoletarget coloredconsoletarget).rowhighlightingrules.add(new consolerowhighlightingrule(conditionparser.parseexpression("level == loglevel.info"), consoleoutputcolor.white, consoleoutputcolor.nochange)); (consoletarget coloredconsoletarget).rowhighlightingrules.add(new consolerowhighlightingrule(conditionparser.parseexpression("level == loglevel.debug"), consoleoutputcolor.gray, consoleoutputcolor.nochange)); (consoletarget coloredconsoletarget).rowhighlightingrules.add(new consolerowhighlightingrule(conditionparser.parseexpression("level == loglevel.trace"), consoleoutputcolor.darkgray, consoleoutputcolor.nochange)); logmanager.configuration.addtarget(consoletarget); } updaterules(consoletarget); logmanager.reconfigexistingloggers(); } public void log(string message) { logmanager.getlogger("customlogger").trace(message); } private void updaterules(target target) { var rules = logmanager.configuration.loggingrules.where(u => u.targets.contains(target)).tolist(); rules.foreach(u => logmanager.configuration.loggingrules.remove(u)); logmanager.configuration.loggingrules.add(new loggingrule("system.net.*", loglevel.trace, target)); //<-- throws exception logmanager.configuration.loggingrules.add(new loggingrule("system.servicemodel.*", loglevel.trace, target)); logmanager.configuration.loggingrules.add(new loggingrule("system.windows.*", loglevel.trace, target)); logmanager.configuration.loggingrules.add(new loggingrule("customlogger", loglevel.trace, target)); } public void addobserver(action<string> addeventlog) { target duplexcallbacktarget; duplexcallbacktarget = logmanager.configuration.findtargetbyname(nameof(duplexcallbacktarget)); if (duplexcallbacktarget == null) { var layout = new xmllayout(); duplexcallbacktarget = new duplexcallbacktarget() { name = nameof(duplexcallbacktarget), layout = layout, callbackaction = addeventlog, }; logmanager.configuration.addtarget(duplexcallbacktarget); } updaterules(duplexcallbacktarget); logmanager.reconfigexistingloggers(); } } [target("duplexcallback")] public class duplexcallbacktarget : targetwithlayout { /// <summary> /// callback action client event viewer. /// </summary> public action<string> callbackaction { get; set; } /// <summary> /// writes specified log event information. /// </summary> /// <param name="logeventinfo">the log event information.</param> protected override void write(logeventinfo logeventinfo) { try { callbackaction(logeventinfo.message); } catch (exception ex) { console.writeline(ex.tostring()); } } } //ninject public static class ioc { public static ikernel kernel = new standardkernel(); }
implementation listener:
public class contractcallback : iduplexcontractcallback { public void logger(string obj) { console.writeline(string.format("client received: {0}", obj)); } public void receivedcalculate(int i) { console.writeline(string.format("client received: {0}", i)); } }
consolewindow listener:
class program { static void main(string[] args) { console.writeline("waiting server ready..."); console.readline(); var binding = new wsdualhttpbinding(); binding.security.mode = wsdualhttpsecuritymode.message; binding.security.message.clientcredentialtype = messagecredentialtype.windows; var factory = new duplexchannelfactory<iduplexcontract>(new instancecontext(new contractcallback()), binding, new endpointaddress("http://address:port/iduplexcontract")); var channel = factory.createchannel(); channel.addlistener(); console.writeline("listening @ server...."); console.readline(); } }
consolewindow client:
class program { static void main(string[] args) { console.writeline("waiting server & listener ready..."); console.readline(); var binding = new basichttpbinding(); binding.security.mode = basichttpsecuritymode.transportcredentialonly; binding.security.transport.clientcredentialtype = httpclientcredentialtype.windows; var factory = new channelfactory<icontract>(binding, new endpointaddress("http://address:port/icontract")); var channel = factory.createchannel(); while (true) { channel.update(console.readline()); } } }
the issue infinity loop. created system.net class because when i'm calling callback function system.net namespace tracing call next server http message. logged , sent logger, etc, etc, etc...
Comments
Post a Comment