是否有任何方法可以将错误日志从事件查看器导入SQL表并每天安排作业。我想使用powershell脚本或SSIS包。
答案 0 :(得分:1)
首先你可以在网上轻松找到答案,但是我也想尝试一下,这里有测试结果。
你可以做这样的事情:
CREATE TABLE WinLogs (
EntryType VARCHAR(255),
[Source] VARCHAR(255),
[Message] VARCHAR(4000),
TimeGenerated datetime
)
Data Flow task
添加到包中; 在内部包添加Script Component
,您应该在其中添加4个输出列(箭头显示要更改的内容):
EntryType(字符串255)
来源(字符串255)
消息(字符串4000)
TimeGenerated(数据库时间戳)
public override void CreateNewOutputRows()
{
// Get all events from the Application(/System/Security) log from the local server (.)
EventLog myEvenLog = new EventLog("Application", ".");
// Create variable to store the entry
EventLogEntry myEntry;
// Loop trough all entries (oldest first)
for (int i = 0; i < myEvenLog.Entries.Count; i++)
{
// Get single entry
myEntry = myEvenLog.Entries[i];
// Add new records
this.Output0Buffer.AddRow();
// Fill columns
this.Output0Buffer.EntryType = myEntry.EntryType.ToString();
this.Output0Buffer.Source = myEntry.Source;
this.Output0Buffer.TimeGenerated = myEntry.TimeGenerated;
// Take a max of 4000 chars
this.Output0Buffer.Message = myEntry.Message.Substring(0, (myEntry.Message.Length > 4000 ? 3999 : myEntry.Message.Length - 1));
}
}
SQL Server Destination
组件(也可以是OLE DB Destination
)
源来自此示例Eventlog as a source