Log4net not logging any errors - log4net

Ive added a log4net implementation to my project but it isnt logging anything at all
In my web.config
<log4net>
<appender name="FileAppender" type="log4net.Appender.SitecoreLogFileAppender, Sitecore.Logging">
<file value="C:\\inetpub\\wwwroot\\Onboarding\\data\\logs\\log.{date}.txt" />
<appendToFile value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%4t %d{ABSOLUTE} %-5p %m%n" />
</layout>
<encoding value="utf-8" />
<filter type="log4net.Filter.LevelRangeFilter">
<param name="LevelMin" value="DEBUG" />
<param name="LevelMax" value="FATAL" />
</filter>
</appender>
</log4net>
In my global.asax:
void Application_Start(object sender, EventArgs e)
{
log4net.Config.XmlConfigurator.Configure();
}
In the class (at the class level) where I log the error
ILog log = LogManager.GetLogger(System.Reflection.MethodBase
.GetCurrentMethod().DeclaringType);
and then in the method itself:
_logger.Log(AusSuperOnboarding.Business.Logging.Enum.Level.Fatal,
GetType().Name, "Exception thrown in SendMessage()", null);

Makes sure the service account user that the web site code runs with has a write access to the path: C:\inetpub\wwwroot\Onboarding\data\logs
If you are using IIS web site, you can check the application pool associated with the site and then right click on the app pool and choose advanced settings, you can see the app pool identity in the Identity field.
View the properties of the log folder, Choose Security tab, click Edit and add the app pool identity user and make sure the "Modify" check box is ticked

Your configuration is incomplete.
You have defined appenders, but no loggers to use them. This means when you create a logger, it has no appenders associated with it, and thus no logging is done.
Add a root element to your config: as log4net loggers are hierarchical, any loggers you create will all inherit the appenders from it:
<root>
<level value="ALL" />
<appender-ref ref="FileAppender" />
<root>

Related

What is the proper format to substitute ConnectionString variable in release pipeline?

I am using following connection string in my web.config file
<configuration>
<connectionString>
<add name="DefaultConnection" connectionString="__DefaultConnection__" providerName="System.Data.SqlClient" />
</connectionString>
<appSettings>
<add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="__ClientValidationEnabled__" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
And in IIS Web Deploy release pipeline I am using XML Variable Substitution, by defining a variable with the key name DefaultConnection and value as Server=127.0.0.1;Database=myDataBase;Trusted_Connection=True;
The variable in appsettings gets changed on the server-side but not for the connectionString, Is it the correct way of declaring connection string. I am doing this for only test purposes, and do not have valid connections setup. Also in Microsoft documentation here, the format is quite different. Can anyone help me, in this case, how can I use this only for test purposes, keeping in mind the IIS server doesn't go down.
As defined in the Microsoft documentation, the connection string will have to be of the same format, as you have used in the variable value like this
Server=127.0.0.1;Database=myDataBase;Trusted_Connection=True
Make these changes in your config file:
<connectionString>
<add name="DefaultConnection" connectionString="Server=local;Database=undefined;Trusted_Connection=False
" providerName="System.Data.SqlClient" />
</connectionString>
Now run your pipelines and you should be able to see changes in web.config on server side.

log exceptions from log4net to azure table storage in net core

I am referring the link to log exceptions from log4net to azure table storage
Here the appender is created, but the log is not entered to azure table storage.
But the way to provide connection string is not there, kindly help to resolve how to provide the connection string for azure table entry
Please let me know if using account_name / account_key is ok for you.
As my mentioned in my previous post, in app.config -> provide the table name / account_name / account_key:
<configuration>
<configSections>
<section name="log4net"
type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<log4net>
<appender name="AzureLogAppender" type="Log4NetAzureTables.AzureLogAppender, Log4NetAzureTables" >
<param name="tableName" value="your table name" />
<param name="accountName" value="your account" />
<param name="accountKey" value="your account key" />
</appender>
<root>
<level value="ALL" />
<appender-ref ref="AzureLogAppender" />
</root>
</log4net>
</configuration>

Deploying a WCF Data Service/REST Service on IIS 7.5 localhost

Here are the details of my problem. I have one simple WCF Data Service (named WCFServiceAppCBS.svc) using an Entity Framework data access layer that talks to a SqlServer 2008 R2 datasource to return some entities. I just want to expose a few tables as "GET" to be later consumed by external getJSON/AJAX calls in some html files.
For development purposes, it works fine when I'm playing around with it in VS2010 using IIS Express and can consume the OData URI and return data. But, the OData service doesn't return anything when I deploy it to the localhost IIS 7.
All I get is the Atom Pub feed that lists my entities, but when I try to execute any type of iQueryable statements (i.e. http://localhost/WCFServiceAppCBS/OData.svc/officers), I get a generic "the website cannot display the page".
I'm not sure if it is having a problem authenticating or if there are other settings in my Web.Config or IIS that I'm missing.
Here's my web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true" />
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<connectionStrings>
<add name="CBSEntities" connectionString="metadata=res://*/CBSLookup.csdl|res://*/CBSLookup.ssdl|res://*/CBSLookup.msl;provider=System.Data.SqlClient;provider connection string="data source=QCSQL2K8DEV;initial catalog=CBS;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
Here's my OData.svc.cs...
using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;
namespace WCFServiceAppCBS
{
public class OData : DataService<CBSEntities>
{
// This method is called only once to initialize service-wide policies.
public static void InitializeService(DataServiceConfiguration config)
{
// TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
// Examples:
config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);
// config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
}
}
}
Thanks for any help you can provide!

How do I access the currently logged in user from new controllers I create?

Here is my problem. I'm building a web application using MVC3 framework. My application started as the sample website included in the MVC3 Installation.
That web application was already setup for users to be able to login.
My problem is this.
I need to save files when the user logs in, I need the files to be created under folders named after the UserName
How do I access the Logged in users info and profile? When I evaluate HttpContext.Current.User It returns my windows NTLM logon name, not the name i logged into the site with. Here is what my web.config looks like.
<profile defaultProvider="AspNetSqlProfileProvider" enabled="true">
<providers>
<clear/>
<add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/" />
</providers>
<properties>
<add name ="TaxPayerID" type="String"/>
</properties>
</profile>
<roleManager enabled="true">
<providers>
<clear/>
<add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/" />
<add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/" />
</providers>
</roleManager>
Your custom controller should inherit from the base Controller class. Access the logged in user via:
User.Identity.Name
I had removed the authentication section of my web.config file. I realized that right after I posted this

Azure Membership UI

Using AspProviders (TableStorageMembershipProvider etc) from Microsoft WCF Azure Samples.
It is WCF Service Web Role, and in Azure Storage Explorer I can see Membership, Roles and Session tables appearing nicely when I try to connect.
But is there any exisiting code to manage Membership and Roles?
Some ASPX pages I guess, something like this for plain old ASP.NET, but more modern and Azure-tested hopefully?
Thanks,
Andres
To my surprise, Peter Kellner's solution I mentioned works just fine. Here are the steps to follow: Add AspProviders (from WCF Azure Samples) to your solution. Create Azure ASP.NET Web Role (let's call it MembershipAdmin), reference AspProviders from it. Add Membership.aspx and other aspx/cs files from Peter Kellner's solution, mark Membership.aspx as "Set As Start Page". In MembershipAdmin's Web.config, find and replace sections "membership" and "roleManager", and add section "appSettings" (the latter goes directly under root configuration). Examples of these sections are below, just change "YourTargetService" to what your real service name is. Actually it's going to mirror Web.config of your real service, regarding these sections (well, you need a few more tricks there, too - as a matter of completeness I'd like to mention I got help from here and here). Then just run, and appearing Membership.aspx is quite self explaining. Of course securing that page will be obviously your next worry, but at least now roles/users can be managed, and they appear nicely into Azure Table Storage.
<membership defaultProvider="TableStorageMembershipProvider" userIsOnlineTimeWindow="20">
<providers>
<clear />
<add name="TableStorageMembershipProvider" type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageMembershipProvider" description="Membership provider using table storage" applicationName="YourTargetService" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" minRequiredPasswordLength="1" minRequiredNonalphanumericCharacters="0" requiresUniqueEmail="true" passwordFormat="Hashed" />
</providers>
</membership>
<roleManager enabled="true" defaultProvider="TableStorageRoleProvider" cacheRolesInCookie="true" cookieName=".ASPXROLES" cookieTimeout="30" cookiePath="/" cookieRequireSSL="false" cookieSlidingExpiration="true" cookieProtection="All">
<providers>
<clear />
<add name="TableStorageRoleProvider" type="Microsoft.Samples.ServiceHosting.AspProviders.TableStorageRoleProvider" description="Role provider using table storage" applicationName="YourTargetService" />
</providers>
</roleManager>
<appSettings>
<add key="TableStorageEndpoint" value="http://127.0.0.1:10002/devstoreaccount1" />
<add key="BlobStorageEndpoint" value="http://127.0.0.1:10000/devstoreaccount1" />
<add key="AccountName" value="devstoreaccount1" />
<add key="AccountSharedKey" value="Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==" />
<add key="DefaultMembershipTableName" value="Membership" />
<add key="DefaultRoleTableName" value="Roles" />
<add key="DefaultSessionTableName" value="Sessions" />
<add key="DefaultProviderApplicationName" value="YourTargetService" />
<add key="DefaultProfileContainerName" />
<add key="DefaultSessionContainerName" />
</appSettings>

Resources