I want to configure Graylog in web.Config file but for some reason, logs are not being sent. (configuring on JSON is not an option):
<add key="serilog:using:Graylog" value="Serilog.Sinks.Graylog" />
<add key="serilog:write-to:Graylog.hostnameOrAdress" value="URL" />
<add key="serilog:write-to:Graylog.port" value="12201" />
<add key="serilog:write-to:Graylog.transportType" value="Http" />
But I checked and I am able to send logs to Graylog if i configure it in my Serilog Init class
var logger = new LoggerConfiguration()
.ReadFrom.AppSettings().WriteTo.Graylog(new GraylogSinkOptions
{
HostnameOrAddress = "URL",
Port = 12201,
TransportType = TransportType.Http
})
.CreateLogger();
What could be the problem?
Just found out my mistake. Made a typo: instead of address I wrote adress :)
wrong:
<add key="serilog:write-to:Graylog.hostnameOrAdress" value="URL" />
should be:
<add key="serilog:write-to:Graylog.hostnameOrAddress" value="URL" />
Related
I'm using Quartz.Server.exe 2.X as job executor.
I'm using Quartz.Server.exe.config to configure quartz.
<quartz >
<add key="quartz.scheduler.instanceName" value="AlyCE_LROScheduler" />
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
<add key="quartz.jobStore.useProperties" value="true" />
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz" />
<add key="quartz.jobStore.tablePrefix" value="QUARTZ_" />
<add key="quartz.jobStore.dataSource" value="defaultDS" />
<add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" />
<add key="quartz.dataSource.defaultDS.provider" value="SqlServer-20" />
<add key="quartz.dataSource.defaultDS.connectionString" value="my connection string to encrypt/decrypt" />
</quartz>
All works fine. Now I'd like to encrypt the connection string for security reason.
Is there a way to let Quartz.Server.exe to understand encrypted connection string?
Thanks
I solved.
I removed the connection string quartz property and I added the connectionProvider.type property, that let me to override the standard Quartz.Impl.AdoJobStore.Common.DbProvider.
So I am able to decrypt my connection string.
So my config looks like this:
<quartz >
<!-- thread pool info -->
<add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" />
<!-- job store info -->
<add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" />
<add key="quartz.jobStore.useProperties" value="true" />
<add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz" />
<add key="quartz.jobStore.tablePrefix" value="QUARTZ_" />
<add key="quartz.jobStore.dataSource" value="defaultDS" />
<add key="quartz.jobStore.lockHandler.type" value="Quartz.Impl.AdoJobStore.UpdateLockRowSemaphore, Quartz" />
<add key="quartz.dataSource.defaultDS.connectionProvider.type" value="MyDll.MyDbProvider, MyDll" />
</quartz>
<connectionStrings>
<add key="myConnString" connectionString="crypted"/>
</connectionStrings>
Then I create new class library project where I created this class:
public class MyDbProvider : DbProvider
{
public MyDbProvider() : base("SqlServer-20", MyHelper.GetConnectionString()) { }
}
public static class MyHelper
{
public static string GetConnectionString()
{
//here i decrypt my connection string from app.config file
}
}
MyDll.dll must be in the same directory of Quartz.Server.exe .
Hope this can help someone!
In previous versions all of these settings could be added and tweaked in the Web.Config file using something like the code below:
<staticContent>
<mimeMap fileExtension=".webp" mimeType="image/webp" />
<!-- Caching -->
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="96:00:00" />
</staticContent>
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
<urlCompression doStaticCompression="true" doDynamicCompression="true"/>
However, with the Web.Config no longer being around in ASP.NET vNext, how do you adjust settings like this? I have searched the net and the ASP.NET Github repo, but not come across anything - any ideas?
As "agua from mars" states in the comments, if you're using IIS you can use IIS's static file handling, in which case you can use the <system.webServer> section in a web.config file and that will work as it always did.
If you're using ASP.NET 5's StaticFileMiddleware then it has its own MIME mappings that come as part of the FileExtensionContentTypeProvider implementation. The StaticFileMiddleware has a StaticFileOptions that you can use to configure it when you initialize it in Startup.cs. In that options class you can set the content type provider. You can instantiate the default content type provider and then just tweak the mappings dictionary, or you can write an entire mapping from scratch (not recommended).
ASP.NET Core - mime mappings:
If the extended set of file types you are providing for the entire site are not going to change, you can configure a single instance of the ContentTypeProvider class, and then leverage DI to use it when serving static files, like so:
public void ConfigureServices(IServiceCollection services)
{
...
services.AddInstance<IContentTypeProvider>(
new FileExtensionConentTypeProvider(
new Dictionary<string, string>(
// Start with the base mappings
new FileExtensionContentTypeProvider().Mappings,
// Extend the base dictionary with your custom mappings
StringComparer.OrdinalIgnoreCase) {
{ ".nmf", "application/octet-stream" }
{ ".pexe", "application/x-pnal" },
{ ".mem", "application/octet-stream" },
{ ".res", "application/octet-stream" }
}
)
);
...
}
public void Configure(
IApplicationBuilder app,
IContentTypeProvider contentTypeProvider)
{
...
app.UseStaticFiles(new StaticFileOptions() {
ContentTypeProvider = contentTypeProvider
...
});
...
}
I trying to configure httpCompression on IIS7. By googling, I found that it can be made using httpCompression section in config. The problem, that I can't make it work from web.config.
When I make the configuration in applicationHost.config everything works as needed, but I want to be able to make this configuration per application and not globally.
I changed section definition in applicationHost.config to <section name="httpCompression" overrideModeDefault="Allow" /> and moved httpCompression section to web.config:
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" />
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/atom+xml" enabled="true" />
<add mimeType="application/xaml+xml" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="application/json" enabled="true" />
<add mimeType="application/json; charset=utf-8" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
</httpCompression>
What am I missing? It looks like IIS not reads compression configurations from web.config at all.
After each change, I make application pool recycle, so it not a problem.
as per this ServerFault answer: https://serverfault.com/a/125156/117212 - you can't change httpCompression in web.config, it needs to be done in applicationHost.config file. Here is the code I use in my Azure web role to modify applicationHost.config file and add mime types for compression:
using (var serverManager = new ServerManager())
{
var config = serverManager.GetApplicationHostConfiguration();
var httpCompressionSection = config.GetSection("system.webServer/httpCompression");
var dynamicTypesCollection = httpCompressionSection.GetCollection("dynamicTypes");
Action<string> fnCheckAndAddIfMissing = mimeType =>
{
if (dynamicTypesCollection.Any(x =>
{
var v = x.GetAttributeValue("mimeType");
if (v != null && v.ToString() == mimeType)
{
return true;
}
return false;
}) == false)
{
ConfigurationElement addElement = dynamicTypesCollection.CreateElement("add");
addElement["mimeType"] = mimeType;
addElement["enabled"] = true;
dynamicTypesCollection.AddAt(0, addElement);
}
};
fnCheckAndAddIfMissing("application/json");
fnCheckAndAddIfMissing("application/json; charset=utf-8");
serverManager.CommitChanges();
}
ServerManager comes from Microsoft.Web.Administration package in NuGet.
You should check the whole config file hierarchy.
If you removed the section from applicationHost you may be inheriting from machine.config or a web.config of a parent directory.
I want to use below code with a website. Which config sections I should add to web.config to log the output into a file or windows eventlog ?
using System.Diagnostics;
// Singleton in real code
Class Logger
{
// In constructor: Trace.AutoFlush = false;
public void Log(message)
{
String formattedLog = formatLog(message);
Trace.TraceInformation(formattedLog);
Trace.Flush();
}
}
You should use system.diagnostics section.
Here's example from MSDN for text file:
<configuration>
<system.diagnostics>
<trace autoflush="false" indentsize="4">
<listeners>
<add name="myListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="TextWriterOutput.log" />
<remove name="Default" />
</listeners>
</trace>
</system.diagnostics>
</configuration>
This is for system events log: http://msdn.microsoft.com/en-us/library/system.diagnostics.eventlogtracelistener.aspx
I'm trying to send an email to an external address as part of a web app. I can send an email fine when using a simple executable running on the server:
private void button1_Click(object sender, EventArgs e)
{
MailMessage message = new MailMessage(welcomeMessageFrom, toAddress, welcomeMessageSubject, welcomeMessageSubject);
SmtpClient emailClient = new SmtpClient("mail.sortuv.com");
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(username, password);
emailClient.UseDefaultCredentials = false;
emailClient.Credentials = SMTPUserInfo;
emailClient.Send(message);
}
However, trying the same code from an ASP.NET page gives the following exception:
Mailbox unavailable. The server response was: 5.7.1 Unable to relay for <user's email>
I'm new to IIS but do you have suggestions on how to debug?
UPDATE: I had to specify the domain for the user as well. Still not sure why a regular .exe was ok without it. Hope this helps someone.
Seems a credential issue. The normal exe runs under your account.
The ASP.NET application run under the NETWORK SERVICE in Windows Server and ASPNET under Windows XP.
You have to use other credentials in order to successfully send email from ASP.NET
Try adding
emailClient .DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
Is this for IIS7 as I had a simular issue I had to enable the smtp service on the server
And set up the mail for each domain on there
Thanks for all the help guys, I just figured it out. I had to specify the domain:
SmtpClient emailClient = new SmtpClient(servername);
System.Net.NetworkCredential SMTPUserInfo = new System.Net.NetworkCredential(name, pass);
SMTPUserInfo.Domain = domain; // i.e. "foo.com"
emailClient.UseDefaultCredentials = false;
emailClient.Credentials = SMTPUserInfo;
emailClient.Send(message);
Are you setting anything your web.config, relating to mail parameters? IIRC, the web.config will override your code settings.
Also, something else you can do, is to enable logging, to actually see what the SmtpClient is sending.
You need to add some values to your .config file. Here is an example:
<configuration>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.Net" >
<listeners>
<add name="MyTraceFile"/>
</listeners>
</source>
<source name="System.Net.Sockets">
<listeners>
<add name="MyTraceFile"/>
</listeners>
</source>
</sources>
<sharedListeners>
<add
name="MyTraceFile"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="System.Net.trace.log" />
</sharedListeners>
<switches>
<add name="System.Net" value="Verbose" />
<add name="System.Net.Sockets" value="Verbose" />
</switches>
</configuration>
Here is a link with more info:
http://systemnetmail.com/faq/4.10.aspx