Configuring Log4NetLoggerFactoryAdapter Programmatically (Trying Again) - log4net

This question was asked here, however the solution was not a programmatic configuration. In this case, a library Wrapper.dll is properly configured with Common.Logging. A console application ConsoleApplication1.exe attempts to implement a Log4NetLoggerFactoryAdapter.
This works fine, sending log entries from Wrapper.dll to the console.
The app.config:
<configSections>
<sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1211">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common>
<log4net>... a valid ConsoleAppender ..</log4net>
The code within ConsoleApplication1:
//var properties = new Common.Logging.Configuration.NameValueCollection();
//properties.Add("configType", "INLINE");
//var adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(properties);
var c1 = new Wrapper();
This does not work. It does not send log entries from Wrapper.dll to the console.
The app.config:
<configSections>
<!-- <sectionGroup name="common">
<section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
</sectionGroup> -->
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<!-- <common>
<logging>
<factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1211">
<arg key="configType" value="INLINE" />
</factoryAdapter>
</logging>
</common> -->
<log4net>... a valid ConsoleAppender ..</log4net>
The code within ConsoleApplication1:
var properties = new Common.Logging.Configuration.NameValueCollection();
properties.Add("configType", "INLINE");
var adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(properties);
var c1 = new Wrapper();
With the programmatic solution I can successfully use GetLogger within ConsoleApplication1 from either the adapter or from log4net, but I cannot get the log events to propagate through from the loggers used in the "Wrapper" library.
Note that in works fine I have allowed the xml and commented the programmatic invocation. In does not work I have commented the relevant xml and implemented the programmatic code. Note also that this is a trivial example. The real application is trying to use a .NET library that implements Common.Logging from Matlab.

After you create the adapter you have to set it as the LogManager's Adapter:
var adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(properties);
Common.Logging.LogManager.Adapter = adapter;
var c1 = new Wrapper();

Related

phonegap ajax call to express.js(node)

I am new to phone gap , Trying to make Ajax call to my Node.js server but it is failing .
here is my node.js simple express code
Server.js file
var express = require('express')
,app = express()
app.get('/',function(req,res){
res.json('{fname:"fname",lname:"lname"}')
})
app.listen(process.env.PORT || 3015)
Here is my index.html ajax call using jquery
<script>
$(document).ready(function () {
$.ajax({
type: "GET",
url: "http://domainName:port/", //change according
success: function (data) {
alert(success)
},
error: function (e) {
alert('Error:');
}
});
})
</script>
Here is my config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.testAndroid2.firstApp2"
versionCode = "1"
version = "1.0.0" >
<!-- versionCode is Android only -->
<!-- version is in major.minor.patch format -->
<name>PhoneGap Example App</name>
<description>
An example for phonegap build app which wont show up in the playstore.
</description>
<author href="https://YourWebsite.com" email="yourEmail#goesHere.com">
Name Of The Author
</author>
<access origin="*" />
<platform name="android">
<allow-intent href="market:*" />
<access origin="*" />
<allow-intent href="*" />
<allow-navigation href="*" />
</platform>
</widget>
Ajax is failing when i build my application using phonegap build and run it on my phone , but same application is working fine in my browser of my PC (i.e there is not AJAX issue) .
Please let me know if i am missing any file in or something as i am completely new to phonegap . Any help would be appreciated .
There was missing Plugin (<plugin name="cordova-plugin-whitelist" source="npm" />) in Config.xml file
**Config.xml file should be like :**
<?xml version="1.0" encoding="UTF-8" ?>
<widget xmlns = "http://www.w3.org/ns/widgets"
xmlns:gap = "http://phonegap.com/ns/1.0"
id = "com.testAndroid4.firstApp4"
versionCode = "1"
version = "1.0.0" >
<!-- versionCode is Android only -->
<!-- version is in major.minor.patch format -->
<name>PhoneGap Example App</name>
<description>
An example for phonegap build app which wont show up in the playstore.
</description>
<author href="https://YourWebsite.com" email="yourEmail#goesHere.com">
Name Of The Author
</author>
<access origin="*" />
<plugin name="cordova-plugin-x-socialsharing" source="npm" />
<plugin name="cordova-plugin-whitelist" source="npm" />
</widget>

ServiceStack with Razor - Model is null (deployed to Azure)

When using ServiceStack / Razor, I'm having issues rendering a view in Azure only.
http://nehcr-dev.azurewebsites.net/with-view
Here is a screenshot of the page locally:
!https://www.dropbox.com/s/up5bmixdjmcc9bi/with-view.png?dl=0
Here is my service response:
return new HttpResult(new IndexResponse("Home | Northeast Healthcare Recruitment")
{
TotalJobs = metadata.TotalJobs,
GroupedJobTypeCounts = groupedJobTypeCounts,
MostRecentJobs = new List<JobListingSummary>()
})
{
View = "Index"
};
where IndexResponse is
public class IndexResponse : BaseResponse
{
public IndexResponse(string title) : base(title) { }
public int TotalJobs { get; set; }
public List<List<JobTypeCount>> GroupedJobTypeCounts { get; set; }
public List<JobListingSummary> MostRecentJobs { get; set; }
}
and BaseResponse is
public abstract class BaseResponse
{
public BaseResponse(string title)
{
if (string.IsNullOrWhiteSpace(title))
{
Title = "Northeast Healthcare Recruitment";
}
Title = title;
}
public string Title { get; set; }
}
the beginning of my view looks like:
#inherits ViewPage<NEHCR.ServiceModel.IndexResponse>
#section head{
}
<section id="content" class="nehcr-content">
<!-- JOB SEARCH START -->
<section class="nehcr-search-hero">
<div class="container">
<div>
<div class="nehcr-search-text">
<h1 class="nehcr-search-text-header">Search from #Model.TotalJobs job offers</h1>
<p class="nehcr-search-text-p">Your career starts here.</p>
</div>
<form method="GET" action="/jobs" class="nehcr-search-wrap nehcr-row">
and my web.config is:
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"/>
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false"/>
</sectionGroup>
</configSections>
<appSettings>
<add key="webPages:Enabled" value="false" />
<add key="ConnectionString" value="" />
</appSettings>
<connectionStrings>
<add name="ConnectionString" connectionString="" providerName="System.Data.SqlClient" />
</connectionStrings>
<!--
For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367.
The following attributes can be set on the <httpRuntime> tag.
<system.Web>
<httpRuntime targetFramework="4.6.2" />
</system.Web>
-->
<system.web>
<compilation debug="true" targetFramework="4.6.2">
<buildProviders>
<add extension=".cshtml" type="ServiceStack.Razor.CSharpRazorBuildProvider, ServiceStack.Razor"/>
</buildProviders>
</compilation>
<httpRuntime targetFramework="4.5"/>
<httpHandlers>
<add path="*" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*"/>
</httpHandlers>
<customErrors mode="Off">
</customErrors>
</system.web>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<urlCompression doStaticCompression="true" doDynamicCompression="false"/>
<handlers>
<add path="*" name="ServiceStack.Factory" type="ServiceStack.HttpHandlerFactory, ServiceStack" verb="*" preCondition="integratedMode" resourceType="Unspecified" allowPathInfo="true"/>
</handlers>
</system.webServer>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<pages pageBaseType="ServiceStack.Razor.ViewPage">
<namespaces>
<add namespace="System"/>
<add namespace="System.Linq"/>
<add namespace="ServiceStack"/>
<add namespace="ServiceStack.Html"/>
<add namespace="ServiceStack.Razor"/>
<add namespace="ServiceStack.Text"/>
<add namespace="ServiceStack.OrmLite"/>
<add namespace="NEHCR"/>
<add namespace="NEHCR.ServiceModel"/>
</namespaces>
</pages>
</system.web.webPages.razor>
Locally it runs fine, IISExpress on Win10. Deployed to Azure I get this:
System.NullReferenceException occurred
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=nmhpfpfd
StackTrace:
at ASP.Views.Home.__Index.Execute() in d:\home\site\wwwroot\Views\Home\Index.cshtml:line 15
at ServiceStack.Razor.ViewPage`1.WriteTo(StreamWriter writer)
at ServiceStack.Razor.Managers.RazorPageResolver.ExecuteRazorPageWithLayout(RazorPage razorPage, IRequest httpReq, IResponse httpRes, Object model, IRazorView pageInstance, Func`1 layout)
at ServiceStack.Razor.Managers.RazorPageResolver.ExecuteRazorPage(IRequest httpReq, IResponse httpRes, Object model, RazorPage razorPage)
at ServiceStack.Razor.Managers.RazorPageResolver.ProcessRequest(IRequest httpReq, IResponse httpRes, Object dto)
at ServiceStack.Formats.HtmlFormat.<>c__DisplayClass10_0.<SerializeToStream>b__0(IViewEngine x)
at ServiceStack.Formats.HtmlFormat.SerializeToStream(IRequest req, Object response, IResponse res)
ServiceStack.Razor.ViewPageBase<TModel>.Model.get returned null.
If I change my service reponse to:
return new IndexResponse("Home | Northeast Healthcare Recruitment")
{
TotalJobs = metadata.TotalJobs,
GroupedJobTypeCounts = groupedJobTypeCounts,
MostRecentJobs = new List<JobListingSummary>()
};
it works fine: http://nehcr-dev.azurewebsites.net/
Thanks for any insight.

RemotingAppender problems. Conn created but nothing appended

I have been learning log4net and wish to use the remoting appender to log messages onto a server sometime in the future. To do this, I first tried creating a local .Net remoting server and appending to it. It seems to me that the server has been created but I cannot receive these messages. (To check this, I try accessing the server by entering localhost:portnumber in my browser, before and after running my program. It fails before and accepts the connection later. Any better way to debug this?)
Anyway, here is the code. I would appreciate any help.
PS: I can see the File & Console appenders work.
Client code
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="log4net" type="log4net.onfig.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
<appender name="Console" type="log4net.Appender.ColoredConsoleAppender">
<mapping>
<level value="DEBUG"/>
<foreColor value="Red, HighIntensity"/>
</mapping>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%class %date [%level] - %message%newline"/>
</layout>
</appender>
<appender name="File" type="log4net.Appender.FileAppender">
<file value="logfile.txt"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%class %date [%level] - %message%newline"/>
</layout>
</appender>
<appender name="RemotingAppender" type="log4net.Appender.RemotingAppender">
<sink value="tcp://localhost:8086/RemoteLogger"/>
<lossy value="false"/>
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%class %date [%level] - %message%newline"/>
</layout>
<bufferSize value="1"/>
<onlyFixPartialEventData value="true"/>
</appender>
<root>
<level value="ALL"/>
<appender-ref ref="Console"/>
<appender-ref ref="RemotingAppender"/>
<appender-ref ref="File"/>
</root>
</log4net>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Server code Appconfig
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.runtime.remoting>
<application name="RemoteLogger">
<channels>
<channel name="logging sink" ref="tcp server" port="8086"/>
</channels>
</application>
</system.runtime.remoting>
</configuration>
Server Code
namespace RemoteAPP
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Listening");
var _sink = new RemoteSink();
_sink.EventsReached += (s,a)=> AddLog(a.LoggingEvents);
RemotingConfiguration.Configure("RemoteAPP.exe.config", false);
//RemotingConfiguration.RegisterWellKnownServiceType(new WellKnownServiceTypeEntry(typeof(RemoteSink), "RemoteLogger", WellKnownObjectMode.SingleCall));
RemotingServices.Marshal(_sink, "RemoteLogger");
Console.ReadLine();
}
private static void AddLog(IEnumerable<LoggingEvent> enumerable)
{
var Logevents = enumerable.ToList();
foreach(var logevent in Logevents)
{
Console.WriteLine(logevent);
}
}
}
public class RemoteSink:MarshalByRefObject,RemotingAppender.IRemoteLoggingSink
{
public class LoggingArgs:EventArgs
{
public IEnumerable<LoggingEvent> LoggingEvents;
}
public EventHandler<LoggingArgs> EventsReached;
void RemotingAppender.IRemoteLoggingSink.LogEvents(LoggingEvent[] events)
{
var ev = EventsReached;
if(ev==null)
{
ev.Invoke(this, new LoggingArgs{LoggingEvents = events});
}
}
}
}
Client Code
class Program
{
static void Main(string[] args)
{
Thread.Sleep(10000);
log4net.ILog log = log4net.LogManager.GetLogger(typeof(Program));
for (int i = 0; i < 1000;i++ )
{
log.Info("Hello world");
log.Debug("This is Debug");
log.Warn("This is Warn");
}
Well,
I found the answer. The code above is correct. Turns out there was some incompatibility between the client and server side of Log4net. Although I installed both from the same source (Nuget), something changed between the two references. After setting log4net's internal debugger property to true, I stumbled across this log message.
log4net:ERROR [RemotingAppender] ErrorCode: GenericFailure. Failed in SendBufferCallback
Googling it led me to here and this is where I suspected something was amiss. Long story short, removed all references to log4net in RemoteAPP and reinstalled via Nuget.
It works now. If someone knows how this occurred, please continue the discussion.

Can't embed image in as3 file while build with ant under linux(debian)

I embedded a png in as3, it's all fine on windows, either use FB4.6 or Ant. But while build with Ant under linux(debian), I got this Error. Image path is /var/lib/jenkins/workspace/q5/dev_Flash/code/Copper/src/assets/c001_up.png. Project name is /var/lib/jenkins/workspace/q5/dev_Flash/code/Copper.
[mxmlc] /var/lib/jenkins/workspace/q5/dev_Flash/code/Copper/src/com/copper/ui/skin/DefaultAssets.as(10): col: 3: Error: unable to resolve 'assets/c001_up.png' for transcoding
[mxmlc]
[mxmlc] [Embed(source = "assets/c001_up.png")]
[mxmlc] ^
[mxmlc]
[mxmlc] /var/lib/jenkins/workspace/q5/dev_Flash/code/Copper/src/com/copper/ui/skin/DefaultAssets.as(10): col: 3: Error: Unable to transcode assets/c001_up.png.
as3 file like this
package com.copper.ui.skin {
/**
*
* #author marzwu
*
*/
public class DefaultAssets extends Assets {
[Embed(source = "assets/c001_up.png")]
private var Button_Up:Class;
My ant file is:
<?xml version="1.0" encoding="UTF-8"?>
Q5客户端构建
<!-- 配置属性 -->
<property file="build.properties" />
<property environment="env" />
<property name="FLEX_HOME" value="${env.FLEX_HOME}" />
<taskdef resource="flexTasks.tasks" classpath="${FLEX_HOME}/ant/lib/flexTasks.jar" />
<target name="compile">
<echo message="${basedir}/../src" />
<compc output="../bin/copper.swc" debug="false" incremental="true">
<!-- 指定Comman项目的源码目录 -->
<source-path path-element="${basedir}/../src" />
<!-- 指定编译的文件列表 -->
<include-sources dir="${basedir}/../src">
<include name="**/*.as" />
</include-sources>
<!-- 将Flex SDK 作为外部库进行引用 -->
<compiler.external-library-path dir="${FLEX_HOME}/frameworks">
<include name="**/*.swc" />
</compiler.external-library-path>
<!-- 添加项目中的SWC包,请注意这里是外部 -->
<compiler.external-library-path dir="../libs">
<include name="**/*.swc" />
</compiler.external-library-path>
<define name="CONFIG::Debug" value="true" />
<define name="CONFIG::Release" value="false" />
<jvmarg value="-Xmx2048m"/>
<jvmarg value="-Xms512m"/>
<jvmarg value="-XX:MaxPermSize=512m"/>
</compc>
<!-- 删除缓存文件 -->
<delete>
<fileset dir="../bin" includes="*.cache" />
</delete>
<echo message="complier Flex Library Project finished!" />
</target>
<target name="deploy">
<antcall target="compile" />
<!--antcall target="copy_to_bin" /-->
<echo>前往查看结果:http://10.0.1.69/q5d/</echo>
<echo message="执行发布" />
</target>
I use jenkins to build my as3 project. It's bother me for many day. Appreciate for your helping.
Oops, compiler can't resolve the path, because I did not notice the "u" between "c001_up.png" is an upper case letter. Windows are not sensitive of letter case, but linux are. My fault, thank you for your time.

CC Validator throws error for dashboard.config file - No loaded type is marked up with a Reflector Type attribute

Think I have messed up the config file for the dashboard.
Error -
No loaded type is marked up with a Reflector Type attribute that matches the XML node(dashboard).
Error comes up when I validate the dashboard.config file in the CC Validator.
This is my dashboard.config file
<?xml version="1.0" encoding="utf-8"?>
<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
<dashboard>
<remoteServices>
<servers>
<!-- Update this list to include all the servers you want to connect to. NB - each server name must be unique -->
<server name="local" url="tcp://localhost:21234/CruiseManager.rem" allowForceBuild="true" allowStartStopBuild="true" backwardsCompatible="false" />
</servers>
</remoteServices>
<plugins>
<farmPlugins>
<farmReportFarmPlugin categories="false" />
<cctrayDownloadPlugin />
<administrationPlugin password="" />
</farmPlugins>
<serverPlugins>
<serverReportServerPlugin />
</serverPlugins>
<projectPlugins>
<projectReportProjectPlugin />
<viewProjectStatusPlugin />
<latestBuildReportProjectPlugin />
<viewAllBuildsProjectPlugin />
</projectPlugins>
<buildPlugins>
<buildReportBuildPlugin>
<xslFileNames>
<xslFile>xsl\header.xsl</xslFile>
<xslFile>xsl\modifications.xsl</xslFile>
</xslFileNames>
</buildReportBuildPlugin>
<buildLogBuildPlugin />
</buildPlugins>
<securityPlugins>
<simpleSecurity />
</securityPlugins>
</plugins>
</dashboard>
</cruisecontrol>
Can anyone please help me on this, and also some tips on how to resolve similar issues would be helpful.
Your dashboard.config file looks a little strange, i dont think it should contain the cruisecontrol node.
I think it should be:
<?xml version="1.0" encoding="utf-8"?>
<dashboard>
<remoteServices>
<servers>
<!-- Update this list to include all the servers you want to connect to. NB - each server name must be unique -->
<server name="local" url="tcp://localhost:21234/CruiseManager.rem" allowForceBuild="true" allowStartStopBuild="true" backwardsCompatible="false" />
</servers>
</remoteServices>
<plugins>
<farmPlugins>
<farmReportFarmPlugin categories="false" />
<cctrayDownloadPlugin />
<administrationPlugin password="" />
</farmPlugins>
<serverPlugins>
<serverReportServerPlugin />
</serverPlugins>
<projectPlugins>
<projectReportProjectPlugin />
<viewProjectStatusPlugin />
<latestBuildReportProjectPlugin />
<viewAllBuildsProjectPlugin />
</projectPlugins>
<buildPlugins>
<buildReportBuildPlugin>
<xslFileNames>
<xslFile>xsl\header.xsl</xslFile>
<xslFile>xsl\modifications.xsl</xslFile>
</xslFileNames>
</buildReportBuildPlugin>
<buildLogBuildPlugin />
</buildPlugins>
<securityPlugins>
<simpleSecurity />
</securityPlugins>
</plugins>
</dashboard>

Resources