I am running a website and a windows service . I am able to change at runtime the level of log of my Website using a page I made, and I would like to do the same for my windows service( ie: using a page to monitor the different levels of Log I am using in the service).
Would you have some tips and tricks to achieve that? Or should I resign and upload a new version of the log4net file every time I need to log things a bit more in details (this upload is a bit tricky and quite annoying to do)?
thanks for your ideas,
[EDIT]
UNfortunately none of the answer listed here are aimed at my problem. Mine is to access the log4net from a service located on a Machine A from a WebSite running on a machine B. So that accessing the Web of MAchine A may allow me to change log level of service thread of Machine B.
If your windows service is using ConfigureAndWatch you should be able to edit the config file just like you do for your website with that page you made if you place the configuration file in a place that is accessible via the web page.
You will also have to change the path to the configuration file you load in your windows service but this should be a solution.
You can modify a config file and have your application pick up the changes. The trick is that you cannot use the app.config/web.config file to do so. Otherwise, it takes a reboot of your application before the changes will take place. Here is a SO question that has a couple answers that might work:
.net dynamically refresh app.config
You can also make changes through code like so:
http://weblogs.asp.net/psteele/archive/2010/05/03/tweaking-log4net-settings-programmatically.aspx
Ok only things I found, it to interface my service and Web Application to access the same table in the database, and make regular check to this table to change log level in servizio.
If someone has a better idea, I am all ears.
Related
I have a .NET a web app that i built for files processing .I am using IIS 7 anonymous user authentication , i also did not require the users to log in, so pretty much any user who has access to the intranet can access the web app.
The users said when two of them try to run their files on app at the same time they receive an error( did not specify it).
My question is :
If i use anonymous authentication is it by default every user will have his\her own session while accessing the app?
Yes, by default every user will have their own session. And anonymous authentication is the default scheme for the web. It is unlikely that any web server, by default, would only allow 1 anonymous user at a time.
Most likely, if your app is doing file processing, you may be dealing with file locks and not an issue with IIS. You want to make sure that your code is written so that, if two or more people access it simultaneously, they can not request to same file. Also, you need to make sure that you are properly closing any file streams you open, even in the case of exceptions. Without seeing the code in question, it would be difficult to impossible to give more specific guidance, but hopefully this will help point you in the correct direction.
Install Elmah to get error report of ypur app!
I have a tough question here and I would like to tap the wisdom of the masses to ensure that I am approaching this issue in the most efficient way possible.
Goal: Move 78 web applications (all configured to be an IIS application under a root website) from a Windows Server 2003 box to a 2012 box with as little coding as possible. The 2012 box has a different subdomain "xxx2.blah.com" and the 03 server is mapped to a "xxx.blah.com" server. In short, the user bookmarks won't work once we migrate so we want to write a redirection utility to assist getting the users to the new xxx2.blach.com location without them noticing.
Current State:It is important to note that each application under the root website in IIS6 is configured to run under its own, and sometimes shared, app pools. Some of the applications have querystring values appended to the end of the .NET request that we want to retain because it affects the UI and other business logic already coded.
We were thinking of removing the files within each application to force IIS to return a 404. Once the 404 occurs, we were wanting to run our custom utility to lookup what the equivalent URL is. Since the 404 is an "error" by all intents and purposes, we were thinking that we could "handle" the error like this (ASP.NET 2.0 : Best Practice for writing Error Page)
Is it possible to write that code once, add the logic to the global.asax file in the root website, and then somehow instruct each web application under that root site to execute the code in the parent site? I know they each run under their own app pool and that may mean that we cannot pass execution off onto another application easily but I could be wrong. In addition, we are hoping to not have to copy/paste code 78 times. Any general "best practices" or advice would be greatly appreciated. Also, adjusting it on the network is not an option as the old xxx.blah.com is on a completely different network than the new xxx2.blah.com network.
#Carl
Thank you very much. I initially missed that those variables were available to me for this purpose! The final solution for me was to set the "Redirect To" textbox to "http://xxx2.blah.com$V?UpdateNote=true&$P". This enables the redirection to occur with both the path and querystring name/value pairs in tact and also allowed me to append my own value so that the application could detect it and display a "This page has moved" message to the user.
Thank you Carl! You da man.
I use the following code to build a desired path for an XML file:
System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
When executed from a Windows Forms application, it returns:
C:\Users\MyUsername\AppData\Roaming\...\Database.xml
When executed from within a Windows Service, it returns:
C:\Windows\system32\config\systemprofile\AppData\Roaming\...\Database.xml
I am now resorting to having a custom installer action persist the path in a registry key since the custom action will have a desktop context. If there is a better approach, please let me know.
What I am really interested in finding out is why the behavior is different in the first place. The Windows Service in question is set up to use the LocalSystem account in case that matters.
Only you know what the specific requirements are for this folder, but if it's to share data between multiple users, ApplicationData is the wrong choice:
The directory that serves as a common repository for application-specific data for the current roaming user.
A roaming user works on more than one computer on a network. A roaming user's profile is kept on a server on the network and is loaded onto a system when the user logs on
See the SpecialFolder enumeration and pick an appropriate value that fits your requirements - one that doesn't depend on a specific user. Most of these start with Common.
I suggest that you should check and make sure that two apps are running by the same user.
I tested your code in both winform app and webservice app, but their values are the same, so I can't find your real problem.
good luck!
We have two separate web applications for a site: One for the site itself, and one for the cms/administration side. I'm not sure why the original developer designed it this way, but whatever.
I am tasked with adding some functionality to the administration side that uploads files. These files then need to exist within the folder structure of the actual site. I was thinking I might have to write a web service that sits on the actual site that accepts the file bytes and file name from a call within the administration site, and creates the file in the correct folder, but I was wondering if anyone had any ideas about a cleaner way to accomplish the same thing.
In general, how would you tackle a scenario where you upload a file on one site, and send it to the directory structure in another?
Thanks in advance!
The solution I ended up going with is to store the full file path to the other site in the web.config. It's not the most elegant solution, but it works and I'm mildly happy with it since it is easily maintainable across dev/staging/production.
You could create a Windows Service to transfer the uploaded files from one folder to another.
After a file is uploaded on the admin site, the windows service moves the file over to the correct location on the other site. You just need to decide how to communicate with the service - you could add details about the uploaded file to a message queue that the service monitors or perhaps you windows service might just watch the upload folder for any new files.
The place where I work has 2 servers and a load balancer. The setup is horrible since I have to manually make sure both servers have the same files. I know there are ways to automate this but it has not been implemented, hopefully soon (I have no control over this). I wrote an application that collects a bunch of information from a user, then creates a folder named after the email of the user in one of the servers. The problem is that I can't control in which server the folder gets created in, so let say a user goes in.. fills his stuff and his folder gets created in server 1, user goes away for a while and goes back to the site but this time the load balancer throws the user into server 2, now the user does something that needs to be saved into his folder but since it didn't created in this server an error occurs. What can I do about this? any suggestions?
Thanks
It sounds like you could solve a few issues by implementing a cloud file service for the file writes such as Amazon S3 http://aws.amazon.com/s3/
Disk size management would no longer be a concern
Files are now written and read from S3 so load balancer concerns are solved
Benefits of a semi-edge network with AWS. (not truly edge but in my experience better than most internally hosted solutions)
Don't store your data in the file system, store it in a database.
If you really can't avoid using the file system, you could look at storing the files in a network share both servers have access to. This would be a terrible hack, however.
It sounds like you may be having a session state issue. It sounds odd the way you describe it, but have a look at this article. It's old, but covers the basics. If it doesn't try googling "asp.net session state web farm"
http://ondotnet.com/pub/a/dotnet/2003/03/24/sessionstate.html
Use NAS or SAN to centralize storage. That same network-accessible storage can store the shared configuration that IIS can be setup to use.
Web Deploy v2 just released from Microsoft, I would encourage the powers that be to investigate that, along with Application Request Routing and the greater Web Farm Framework.
This is a normal infrastructure setup. Below are the two commonly used solutions for the situation you are in.
If you have network attached storage available (e.g. Netapps), you can use this storage to centrally store all of your user files that need to be available across all servers in your web farm.
Redesign your application to store all user specific data in a database.