I am integrating NLog logging in a WCF service hosted in IIS 7.5. Multiple instances (different versions) of the service are installed under the same site, so I would like the Application name to be part of the logging path.
I am aware of the NLog.Web extension and the ${iis-site-name} but since the site is common to all instances it is the application name below site level I would like to use in the log file path.
Each of the applications are installed from separate baseDirs but I would prefer to have logs in a folder structure away from the baseDir.
Any hints to getting the application name? When searching for answers most threads leads to HostingEnvironment.SiteName but I have not been able to find similar ways to get the application name.
Thanks in advance.
You can use the HostingEnvironment.ApplicationVirtualPath property and then hookup an NLog layout renderer.
This should work for NLog 4.4 and newer:
LayoutRenderer.Register("iis-application-name", (logEvent) => HostingEnvironment.ApplicationVirtualPath);
Then you can use ${iis-application-name} in your NLog config file.
Just remember to register the renderer before doing anything else, that is do it before you start loggin.
Related
I have tried to google a lot to find a solution to how to host multiple WCF web services on local IIS 6.
So i am asking here. If I can get a step of procedure then i would be glad.
To accomplish your goal this is how to do it:
Create your new solution or just reuse current solution you have.
Create new Project under Visual C# and select WCF Service Application. For sample purposes we name it MultipleHostService project.
It will produce three files named IService1.cs, Service1.svc and Web.config
Under your MultipleHostService project add another New item, under Visual C# Select WCF Service and leave name as is.
It will product addition two files named Iservice2.cs and Service2.svc
Open your Web.Config add Behaviors and Binding configuration highlighted with red box.
If you notice we added Services node and service under it? That is the part that allows us to specify multiple services.
Now click MultipleHostService project
Click Properties
Click Web Tab
In the Servers panel
Select Local IIS in the dropdown list
And under Project URL type this : http://localhost/MultipleHostService "You can change it later on if you want"
And click Create Virtual Directory.
Build the Project MultipleHostService ( Make it sure no failed shown in Error List )
Go to browser and type the follow:
http://localhost/MultipleHostService/Service1.svc
http://localhost/MultipleHostService/Service2.svc
You should see something in the browser like this:
Tools and settings I've used:
Visual Studio 2013
IIS 7
.Net Framework 4.5
Improvements :
You can refactor proper naming for your services.
Remove unnecessary XML node in the configuration file like unused behavior.
Disclaimer : I haven't tested it using IIS 6 but I'm confident that it works on IIS7. Configuration about IIS is not part of this topic so you migt run
some issues which I'm not aware of. There are also some other ways to accomplish multiple hosting of services but this topic is focusing on usage of configuration file. And please do some study on proper Bindings, Behavior and MetaDataExhange which I didn't discuss here.
I have a Big Application build in asp.net 4.5.1 Web form. The Application has two Windows Services. This is a product that we host for different vendors. The client Requirement is to have Separate URL, Database and separate Services. we are getting vendors rapidly, now this became a big problem for me, to update, each url separately, to trace any db changes across the database and implement that separately, and to create separate windows service applications for each vendor and to install that separately on the server. Although I have put code in class libraries so that is shared among all the web and the Windows Service application. but there are other settings, like encryption key, the connection strings to each database, the email settings etc.
can someone please guide me how can I manage multiple copy of same application when there are Windows Service applications too.
Thanks in Advance
I am doing similar things by using different build configurations for that.
Create a new build (solution) configuration for each customer. Right click solution and select 'Configuration Manager'.
Add new configuration with customer name and select to copy settings preferably from Release config.
Once you've done that you are able to switch between those configs next to the debug button in VS.
Go to your web project, right click your Web.config file and select 'Add config Transform'
New config files are created (Web.[ConfigName].config) and placed as sub node under the Web.config file.
These new files are used to transform the original Web.config depending on the selected solution configuration. There's some information in the transform file on how to use it, it is not difficult.
If you would go for automated build process later on, the solution config is the key for that as well. Also if you define publish templates (e.g. to create web deploy packages), you are able to select the config. The transformed web.config is then automatically put into the package.
I am using the Nuget Packager extension to create a Nuget Package to include my Logger project and Nlog. I have this working correctly but had a question about how do i use the correct config file for multiple environments (Dev/QA/Prod)?
Do I have multiple config files, one for each environment in the package? but how does the correct one get applied in QA for example, since different environments might have different listeners or targets? Whats the best way to accomplish this, an example to show how to do this would be great since i am new to Nuget and Nlog.Thanks for your help!
Nlog supports different locations of its config file. One of the location is the main configuration file of application. For more information please see Nlog documentation
Then we can use config transformations option. Visual studio supports this by default for web firendly projects (ASP.NET MVC, WCF etc.). If you application is of different type you can use an extension called SlowCheetah(NuGet Link). More information can be found at this page.
Config transformation deped on build configurations in visual studio. In web project you can see that web.config has two transformations: web.Debug.config and web.Release.config.
Hope it helps
I'm following Microsoft's tutorial on the topic here but it's not working and several items are unclear to me.
http://msdn.microsoft.com/en-us/library/ms733766.aspx
In step 2 it says, "ensure that ASP.NET has access to the contents of the folder". How can i do this?
Is it correct that the .cs code not be compiled? I've never ran .cs as a script of any kind.
Here is my error:
HTTP Error 404.17 - Not Found
The requested content appears to be script and will not be served by the static file handler.
Thanks.
Could you please ensure that your apppool in which your site is running in "Integrated" mode rather than Classic.
If the problem is not resolved after doing this, try to register your IIS with .netv4.0
For doing that
Go to Command Prompt
Go to the location C:\Windows\Microsoft.NET\Framework\v4.0.30319
Register the IIS using aspnet_regiis -i command
Open IISManager and go to handler mappings and right click on the static file and select "Revert to Parent"
You can Host a WCF App/Service in IIS as you host simple website. It seems to me that you are trying to access/browse .cs file. If so, then it is not possible as it is code file. You should browse only your service file i.e. .svc file.
You can refer http://adarshdchaurasia.wordpress.com/2013/09/26/create-restful-wcf-service-api-using-get-post-step-by-step-guide/ to create a WCF service.
Please ensure that:
You have .Net framework 4.0 installed and enabled on your machine. If
not, install or try to re-install. Sometimes re-installation fix the
unknown settings problem we accidentally create.
First try to host a simple demo web site to check if the problem is
with your WCF application or with hosting process your are
following.
In step 2 it says, "ensure that ASP.NET has access to the contents of
the folder". How can i do this?
I think it mean make sure your folder are accessible by the IIS_IUSRS
Check the publish folder properties -> Security tab -> group or user name.
Make sure the app is using application pool with correct .net framework version.
normally I will just set .net framework v4.0.30319
I know similar flavors of this question has been asked before, but I am asking something a little different. I know how to use applicationSettings and such, but what I am trying to do is to make it into a config. i.e., I have a web application which as a reference to a class library. This class library has a reference to a web service. In doing that, it created a .settings file. When I am using this class library in the web application, everything works fine locally. However, in staging and production, I would like to have different URLs for the web service - the only way to do that seems to take the applicationSettings section, and put it in the web.config of the web application project. I'm trying to avoid muddying up the web.config, so is there a way to have this applicationSettings section in another files referenced by the web.config?
<appsSettings configSource="appSettings.config" />
This moves the whole app settings section to a separate file.